Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Added support for `attribute_count_limit` and `attribute_value_length_limit` in tracer provider configuration in `go.opentelemetry.io/contrib/otelconf`. (#8687)
- Added support for `attribute_count_limit` and `attribute_value_length_limit` in logger provider configuration in `go.opentelemetry.io/contrib/otelconf`. (#8686)
- Added support for `server.address` and `server.port` attributes in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#8723)
- Support `OTEL_SEMCONV_STABILITY_OPT_IN` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. Supported values are `rpc` (default), `rpc/dup` and `rpc/old`. (#8726)

### Changed

Expand Down
32 changes: 32 additions & 0 deletions instrumentation/google.golang.org/grpc/otelgrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.g

import (
"context"
"os"
"strings"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -29,6 +31,14 @@ type InterceptorFilter func(*InterceptorInfo) bool
// A Filter must return true if the request should be instrumented.
type Filter func(*stats.RPCTagInfo) bool

type semconvMode int

const (
semconvModeNew semconvMode = iota // Default
semconvModeOld
semconvModeDup
)

// config is a group of options for this instrumentation.
type config struct {
Filter Filter
Expand All @@ -47,6 +57,8 @@ type config struct {

ReceivedEvent bool
SentEvent bool

semconvMode semconvMode
}

// Option applies an option value for a config.
Expand All @@ -66,13 +78,33 @@ func newConfig(opts []Option) *config {
Propagators: otel.GetTextMapPropagator(),
TracerProvider: otel.GetTracerProvider(),
MeterProvider: otel.GetMeterProvider(),
semconvMode: parseSemconvMode(),
}
for _, o := range opts {
o.apply(c)
}

return c
}

func parseSemconvMode() semconvMode {
val := os.Getenv("OTEL_SEMCONV_STABILITY_OPT_IN")
if val == "" {
return semconvModeNew
}
parts := strings.SplitSeq(val, ",")
for p := range parts {
p = strings.TrimSpace(p)
if p == "rpc/dup" {
return semconvModeDup
}
if p == "rpc/old" {
return semconvModeOld
}
}
return semconvModeNew
}

// WithPublicEndpoint configures the Handler to link the span with an incoming
// span context. If this option is not provided, then the association is a child
// association instead of a link.
Expand Down
62 changes: 62 additions & 0 deletions instrumentation/google.golang.org/grpc/otelgrpc/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otelgrpc

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseSemconvMode(t *testing.T) {
tests := []struct {
name string
val string
want semconvMode
}{
{
name: "empty",
val: "",
want: semconvModeNew,
},
{
name: "old",
val: "rpc/old",
want: semconvModeOld,
},
{
name: "dup",
val: "rpc/dup",
want: semconvModeDup,
},
{
name: "unknown",
val: "unknown",
want: semconvModeNew,
},
{
name: "multiple with valid",
val: "foo, rpc/dup",
want: semconvModeDup,
},
{
name: "multiple with old first",
val: "rpc/old, rpc/dup",
want: semconvModeOld,
},
{
name: "spaces",
val: " rpc/old ",
want: semconvModeOld,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("OTEL_SEMCONV_STABILITY_OPT_IN", tt.val)
got := parseSemconvMode()
assert.Equal(t, tt.want, got)
})
}
}
Loading
Loading