Skip to content

Commit 2bd0e1a

Browse files
MrAliasMadVikingGodhanyuancheungtklauserPetrie
authored
Merge main into new_sdk/main (#2996)
* Use already enabled revive linter and add depguard (#2883) * Refactor golangci-lint conf Order settings alphabetically. * Add revive settings to golangci conf * Check blank imports * Check bool-literal-in-expr * Check constant-logical-expr * Check context-as-argument * Check context-key-type * Check deep-exit * Check defer * Check dot-imports * Check duplicated-imports * Check early-return * Check empty-block * Check empty-lines * Check error-naming * Check error-return * Check error-strings * Check errorf * Stop ignoring context first arg in tests * Check exported comments * Check flag-parameter * Check identical branches * Check if-return * Check increment-decrement * Check indent-error-flow * Check deny list of go imports * Check import shadowing * Check package comments * Check range * Check range val in closure * Check range val address * Check redefines builtin id * Check string-format * Check struct tag * Check superfluous else * Check time equal * Check var naming * Check var declaration * Check unconditional recursion * Check unexported return * Check unhandled errors * Check unnecessary stmt * Check unnecessary break * Check waitgroup by value * Exclude deep-exit check in example*_test.go files * Move the minimum version to go 1.17 (#2917) * Move the minimum version to go 1.17 * Update readme and changelog Co-authored-by: Chester Cheung <[email protected]> * Use ByteSliceToString from golang.org/x/sys/unix (#2924) Use unix.ByteSliceToString to convert Utsname []byte fields to strings. This also allows to drop the charsToString helper which serves the same purpose and matches ByteSliceToString's implementation. Signed-off-by: Tobias Klauser <[email protected]> Co-authored-by: Tyler Yahn <[email protected]> * docs: fix typo (#2935) * add timeout to grpc connection in otel-collector example (#2939) * Closes: #2951 (#2952) This PR updates the example listed in the getting started doc so that it will compile without error. It also makes this example consistent with the code found in https://github.com/open-telemetry/opentelemetry-go/blob/main/example/fib/main.go Signed-off-by: Brad Topol <[email protected]> * fix data-model link (#2955) * Bump go.opentelemetry.io/proto/otlp from v0.16.0 to v0.18.0 (#2960) * Move to using Instrumentation Scope (#2976) * Move to using Instrumentation Scope * Use type alias, not definition * Add a changelog entry * docs(website_docs): fix exporting_data.md and getting-started.md toc (#2930) * docs(website_docs): fix toc * docs(website_docs): fix toc * update exporting_data.md for rerun check-links * update exporting_data.md for rerun check-links Co-authored-by: Chester Cheung <[email protected]> Co-authored-by: Tyler Yahn <[email protected]> * Update getting-started.md (#2984) grammar edit for line 175 of readme * fix typo (#2986) * fix typo * spell fix * typo fix (#2991) * added traces.txt to gitignore for fib (#2993) * Deprecate Library and move all uses to Scope (#2977) * Deprecate Library and move all uses to Scope * Add PR number to changelog * Don't change signatures in stable modules * Revert some changes * Rename internal struct names * A bit more renaming * Update sdk/trace/span.go Co-authored-by: Tyler Yahn <[email protected]> * Update based on feedback * Revert change Co-authored-by: Tyler Yahn <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]> * Feat/bridge support text map (#2911) * feat: support TextMap * doc: add comment * test: support for ot.TextMap * Retrieve lost code due to merge * fix: retrieve lost code due to merge. test: support for ot.HTTPHeaders * go mod tidy * Optimized code style, add changelog * doc: Restore comments * wip: add test cases * test: fix args error * delete empty line * Fix syntax and changelog errors * Fix formatting errors Co-authored-by: Chester Cheung <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]> * Add a release template (#2863) * Add a release template * Update the about field Co-authored-by: Damien Mathieu <[email protected]> * Fix linting Issues * Add ignore for template link Co-authored-by: Damien Mathieu <[email protected]> Co-authored-by: Chester Cheung <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]> * Fix merge of CHANGELOG.md Co-authored-by: Aaron Clawson <[email protected]> Co-authored-by: Chester Cheung <[email protected]> Co-authored-by: Tobias Klauser <[email protected]> Co-authored-by: petrie <[email protected]> Co-authored-by: Damien Mathieu <[email protected]> Co-authored-by: Brad Topol <[email protected]> Co-authored-by: Craig Pastro <[email protected]> Co-authored-by: Kshitija Murudi <[email protected]> Co-authored-by: Petrie Liu <[email protected]> Co-authored-by: Guangya Liu <[email protected]> Co-authored-by: Craig Pastro <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]> Co-authored-by: ttoad <[email protected]>
1 parent c250227 commit 2bd0e1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+775
-213
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Version Release
3+
about: Checklist to follow when shipping a new release.
4+
title: 'Release <V1.x.x> Checklist'
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!-- markdownlint-disable MD034 -->
11+
<!--- The current milestones can be found at https://github.com/open-telemetry/opentelemetry-go/milestones -->
12+
- [ ] Complete [Milestone](https://github.com/open-telemetry/opentelemetry-go/milestone/<Release Milesone>)
13+
<!-- markdownlint-enable MD034 -->
14+
- [ ] Update contrib codebase to support changes about to be released (use a git sha version)
15+
- [ ] [Pre-release](https://github.com/open-telemetry/opentelemetry-go/blob/main/RELEASING.md#pre-release)
16+
- [ ] [Tag](https://github.com/open-telemetry/opentelemetry-go/blob/main/RELEASING.md#tag)
17+
- [ ] [Release](https://github.com/open-telemetry/opentelemetry-go/blob/main/RELEASING.md#release)
18+
- [ ] [Check examples](https://github.com/open-telemetry/opentelemetry-go/blob/main/RELEASING.md#verify-examples)
19+
- [ ] [Sync with Contrib](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md#upgrade-goopentelemetryiootel-packages)
20+
- [ ] [Release contrib](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md#release-process)
21+
- [ ] [Sync website docs](https://github.com/open-telemetry/opentelemetry-go/blob/main/RELEASING.md#website-documentation)
22+
- [ ] Close the milestone

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ coverage.*
1111
gen/
1212

1313
/example/fib/fib
14+
/example/fib/traces.txt
1415
/example/jaeger/jaeger
1516
/example/namedtracer/namedtracer
1617
/example/opencensus/opencensus

.lycheeignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
http://localhost
22
http://jaeger-collector
3+
https://github.com/open-telemetry/opentelemetry-go/milestone/

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Add support for `opentracing.TextMap` format in the `Inject` and `Extract` methods
14+
of the `"go.opentelemetry.io/otel/bridge/opentracing".BridgeTracer` type. (#2911)
15+
1116
### Changed
1217

1318
- The `crosslink` make target has been updated to use the `go.opentelemetry.io/build-tools/crosslink` package. (#2886)
19+
- In the `go.opentelemetry.io/otel/sdk/instrumentation` package rename `Library` to `Scope` and alias `Library` as `Scope` (#2976)
1420

1521
### Removed
1622

1723
- Support for go1.16. Support is now only for go1.17 and go1.18 (#2917)
1824

25+
### Deprecated
26+
27+
- The `Library` struct in the `go.opentelemetry.io/otel/sdk/instrumentation` package is deprecated.
28+
Use the equivalent `Scope` struct instead. (#2977)
29+
- The `ReadOnlySpan.InstrumentationLibrary` method from the `go.opentelemetry.io/otel/sdk/trace` package is deprecated.
30+
Use the equivalent `ReadOnlySpan.InstrumentationScope` method instead. (#2977)
31+
1932
## [1.7.0/0.30.0] - 2022-04-28
2033

2134
### Added

baggage/baggage.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (p Property) Key() string {
157157
return p.key
158158
}
159159

160-
// Value returns the Property value. Additionally a boolean value is returned
160+
// Value returns the Property value. Additionally, a boolean value is returned
161161
// indicating if the returned value is the empty if the Property has a value
162162
// that is empty or if the value is not set.
163163
func (p Property) Value() (string, bool) {
@@ -392,7 +392,7 @@ func New(members ...Member) (Baggage, error) {
392392
}
393393
}
394394

395-
// Check member numbers after deduplicating.
395+
// Check member numbers after deduplication.
396396
if len(b) > maxMembers {
397397
return Baggage{}, errMemberNumber
398398
}
@@ -454,7 +454,7 @@ func Parse(bStr string) (Baggage, error) {
454454
func (b Baggage) Member(key string) Member {
455455
v, ok := b.list[key]
456456
if !ok {
457-
// We do not need to worry about distiguising between the situation
457+
// We do not need to worry about distinguishing between the situation
458458
// where a zero-valued Member is included in the Baggage because a
459459
// zero-valued Member is invalid according to the W3C Baggage
460460
// specification (it has an empty key).

bridge/opentracing/bridge.go

+153-14
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func (s fakeSpan) SpanContext() trace.SpanContext {
634634
// Inject is a part of the implementation of the OpenTracing Tracer
635635
// interface.
636636
//
637-
// Currently only the HTTPHeaders format is supported.
637+
// Currently only the HTTPHeaders and TextMap formats are supported.
638638
func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier interface{}) error {
639639
bridgeSC, ok := sm.(*bridgeSpanContext)
640640
if !ok {
@@ -643,38 +643,75 @@ func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier int
643643
if !bridgeSC.otelSpanContext.IsValid() {
644644
return ot.ErrInvalidSpanContext
645645
}
646-
if builtinFormat, ok := format.(ot.BuiltinFormat); !ok || builtinFormat != ot.HTTPHeaders {
646+
647+
builtinFormat, ok := format.(ot.BuiltinFormat)
648+
if !ok {
647649
return ot.ErrUnsupportedFormat
648650
}
649-
hhcarrier, ok := carrier.(ot.HTTPHeadersCarrier)
650-
if !ok {
651-
return ot.ErrInvalidCarrier
651+
652+
var textCarrier propagation.TextMapCarrier
653+
654+
switch builtinFormat {
655+
case ot.HTTPHeaders:
656+
hhcarrier, ok := carrier.(ot.HTTPHeadersCarrier)
657+
if !ok {
658+
return ot.ErrInvalidCarrier
659+
}
660+
661+
textCarrier = propagation.HeaderCarrier(hhcarrier)
662+
case ot.TextMap:
663+
if textCarrier, ok = carrier.(propagation.TextMapCarrier); !ok {
664+
var err error
665+
if textCarrier, err = newTextMapWrapperForInject(carrier); err != nil {
666+
return err
667+
}
668+
}
669+
default:
670+
return ot.ErrUnsupportedFormat
652671
}
653-
header := http.Header(hhcarrier)
672+
654673
fs := fakeSpan{
655674
Span: noopSpan,
656675
sc: bridgeSC.otelSpanContext,
657676
}
658677
ctx := trace.ContextWithSpan(context.Background(), fs)
659678
ctx = baggage.ContextWithBaggage(ctx, bridgeSC.bag)
660-
t.getPropagator().Inject(ctx, propagation.HeaderCarrier(header))
679+
t.getPropagator().Inject(ctx, textCarrier)
661680
return nil
662681
}
663682

664683
// Extract is a part of the implementation of the OpenTracing Tracer
665684
// interface.
666685
//
667-
// Currently only the HTTPHeaders format is supported.
686+
// Currently only the HTTPHeaders and TextMap formats are supported.
668687
func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.SpanContext, error) {
669-
if builtinFormat, ok := format.(ot.BuiltinFormat); !ok || builtinFormat != ot.HTTPHeaders {
688+
builtinFormat, ok := format.(ot.BuiltinFormat)
689+
if !ok {
670690
return nil, ot.ErrUnsupportedFormat
671691
}
672-
hhcarrier, ok := carrier.(ot.HTTPHeadersCarrier)
673-
if !ok {
674-
return nil, ot.ErrInvalidCarrier
692+
693+
var textCarrier propagation.TextMapCarrier
694+
695+
switch builtinFormat {
696+
case ot.HTTPHeaders:
697+
hhcarrier, ok := carrier.(ot.HTTPHeadersCarrier)
698+
if !ok {
699+
return nil, ot.ErrInvalidCarrier
700+
}
701+
702+
textCarrier = propagation.HeaderCarrier(hhcarrier)
703+
case ot.TextMap:
704+
if textCarrier, ok = carrier.(propagation.TextMapCarrier); !ok {
705+
var err error
706+
if textCarrier, err = newTextMapWrapperForExtract(carrier); err != nil {
707+
return nil, err
708+
}
709+
}
710+
default:
711+
return nil, ot.ErrUnsupportedFormat
675712
}
676-
header := http.Header(hhcarrier)
677-
ctx := t.getPropagator().Extract(context.Background(), propagation.HeaderCarrier(header))
713+
714+
ctx := t.getPropagator().Extract(context.Background(), textCarrier)
678715
bag := baggage.FromContext(ctx)
679716
bridgeSC := &bridgeSpanContext{
680717
bag: bag,
@@ -692,3 +729,105 @@ func (t *BridgeTracer) getPropagator() propagation.TextMapPropagator {
692729
}
693730
return otel.GetTextMapPropagator()
694731
}
732+
733+
// textMapWrapper Provides operating.TextMapWriter and operating.TextMapReader to
734+
// propagation.TextMapCarrier compatibility.
735+
// Usually, Inject method will only use the write-related interface.
736+
// Extract method will only use the reade-related interface.
737+
// To avoid panic,
738+
// when the carrier implements only one of the interfaces,
739+
// it provides a default implementation of the other interface (textMapWriter and textMapReader).
740+
type textMapWrapper struct {
741+
ot.TextMapWriter
742+
ot.TextMapReader
743+
readerMap map[string]string
744+
}
745+
746+
func (t *textMapWrapper) Get(key string) string {
747+
if t.readerMap == nil {
748+
t.loadMap()
749+
}
750+
751+
return t.readerMap[key]
752+
}
753+
754+
func (t *textMapWrapper) Set(key string, value string) {
755+
t.TextMapWriter.Set(key, value)
756+
}
757+
758+
func (t *textMapWrapper) Keys() []string {
759+
if t.readerMap == nil {
760+
t.loadMap()
761+
}
762+
763+
str := make([]string, 0, len(t.readerMap))
764+
for key := range t.readerMap {
765+
str = append(str, key)
766+
}
767+
768+
return str
769+
}
770+
771+
func (t *textMapWrapper) loadMap() {
772+
t.readerMap = make(map[string]string)
773+
774+
_ = t.ForeachKey(func(key, val string) error {
775+
t.readerMap[key] = val
776+
777+
return nil
778+
})
779+
}
780+
781+
func newTextMapWrapperForExtract(carrier interface{}) (*textMapWrapper, error) {
782+
t := &textMapWrapper{}
783+
784+
reader, ok := carrier.(ot.TextMapReader)
785+
if !ok {
786+
return nil, ot.ErrInvalidCarrier
787+
}
788+
789+
t.TextMapReader = reader
790+
791+
writer, ok := carrier.(ot.TextMapWriter)
792+
if ok {
793+
t.TextMapWriter = writer
794+
} else {
795+
t.TextMapWriter = &textMapWriter{}
796+
}
797+
798+
return t, nil
799+
}
800+
801+
func newTextMapWrapperForInject(carrier interface{}) (*textMapWrapper, error) {
802+
t := &textMapWrapper{}
803+
804+
writer, ok := carrier.(ot.TextMapWriter)
805+
if !ok {
806+
return nil, ot.ErrInvalidCarrier
807+
}
808+
809+
t.TextMapWriter = writer
810+
811+
reader, ok := carrier.(ot.TextMapReader)
812+
if ok {
813+
t.TextMapReader = reader
814+
} else {
815+
t.TextMapReader = &textMapReader{}
816+
}
817+
818+
return t, nil
819+
}
820+
821+
type textMapWriter struct {
822+
}
823+
824+
func (t *textMapWriter) Set(key string, value string) {
825+
// maybe print a warning log.
826+
}
827+
828+
type textMapReader struct {
829+
}
830+
831+
func (t *textMapReader) ForeachKey(handler func(key, val string) error) error {
832+
return nil // maybe print a warning log.
833+
}

0 commit comments

Comments
 (0)