Skip to content

Commit 158bafc

Browse files
prestonvasquezpellareddmathieu
authored
feat: Support mixed categories for semconv opt-in (#7274)
Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Damien Mathieu <[email protected]>
1 parent a35d2d8 commit 158bafc

File tree

15 files changed

+289
-18
lines changed

15 files changed

+289
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
6868
- Removed a duplicate instance of the `Changed` subheader under `1.18.0/0.43.0/0.12.0` in `./CHANGELOG.md`. (#7163)
6969
- Check for TLS related options to be set before creating TLS config `go.opentelemetry.io/contrib/otelconf`. (#6984)
7070
- Fixed handling of the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#7215)
71+
- Support mixed categories for `OTEL_SEMCONV_STABILITY_OPT_IN` opt-in in the following packages. (#7246)
72+
- `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful`.
73+
- `go.opentelemetry.io/contrib/instrumentation/gin-gonic/gin/otelgin`.
74+
- `go.opentelemetry.io/contrib/instrumentation/gorilla/mux/otelmux`.
75+
- `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo`.
76+
- `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`.
77+
- `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`.
7178

7279
### Removed
7380

instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/env.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/env_test.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/env.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/env_test.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/env.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/env_test.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,38 @@ func WithCommandAttributeDisabled(disabled bool) AttributeOption {
6565
}
6666
}
6767

68+
// hasOptIn returns true if the comma-separated version string contains the
69+
// exact optIn value.
70+
func hasOptIn(version, optIn string) bool {
71+
for _, v := range strings.Split(version, ",") {
72+
if strings.TrimSpace(v) == optIn {
73+
return true
74+
}
75+
}
76+
return false
77+
}
78+
6879
// CommandStartedTraceAttrs generates trace attributes for a CommandStartedEvent
6980
// based on the EventMonitor version.
7081
func (m EventMonitor) CommandStartedTraceAttrs(
7182
evt *event.CommandStartedEvent,
7283
opts ...AttributeOption,
7384
) []attribute.KeyValue {
74-
switch m.version {
75-
case semconvOptIn1260:
85+
// Dup implies both v1.26.0 and v1.21.0
86+
if hasOptIn(m.version, semconvOptInDup) {
87+
return append(
88+
commandStartedTraceAttrsV1260(evt, opts...),
89+
commandStartedTraceAttrsV1210(evt, opts...)...,
90+
)
91+
}
92+
93+
// Check for the 1.26.0 opt-in
94+
if hasOptIn(m.version, semconvOptIn1260) {
7695
return commandStartedTraceAttrsV1260(evt, opts...)
77-
case semconvOptInDup:
78-
return append(commandStartedTraceAttrsV1260(evt, opts...), commandStartedTraceAttrsV1210(evt, opts...)...)
79-
default:
80-
return commandStartedTraceAttrsV1210(evt, opts...)
8196
}
97+
98+
// Fallback to v1.21.0
99+
return commandStartedTraceAttrsV1210(evt, opts...)
82100
}
83101

84102
// peerInfo extracts the hostname and port from a CommandStartedEvent.

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ func TestCommandStartedTraceAttrs(t *testing.T) {
135135
version: "database/dup",
136136
want: append(v1210, v1260...),
137137
},
138+
{
139+
name: "mixed categories",
140+
initAttrs: []attribute.KeyValue{},
141+
version: "database/dup,http",
142+
want: append(v1210, v1260...),
143+
},
138144
}
139145

140146
for _, test := range tests {

instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/env.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)