Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OTel recommended naming for instrumentation scope #507

Merged
merged 7 commits into from
Nov 16, 2023
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

## [Unreleased]

### Changed

- The instrumentation scope name for the `database/sql` instrumentation is now `go.opentelemtry.io/auto/database/sql`. (#507)
- The instrumentation scope name for the `gin` instrumentation is now `go.opentelemtry.io/auto/github.com/gin-gonic/gin`. (#507)
- The instrumentation scope name for the `google.golang.org/grpc/client` instrumentation is now `go.opentelemtry.io/auto/google.golang.org/grpc`. (#507)
- The instrumentation scope name for the `google.golang.org/grpc/server` instrumentation is now `go.opentelemtry.io/auto/google.golang.org/grpc`. (#507)
- The instrumentation scope name for the `net/http/client` instrumentation is now `go.opentelemtry.io/auto/net/http`. (#507)
- The instrumentation scope name for the `net/http/server` instrumentation is now `go.opentelemtry.io/auto/net/http`. (#507)

## [v0.8.0-alpha] - 2023-11-14

### Added
Expand Down
18 changes: 11 additions & 7 deletions internal/pkg/instrumentation/bpf/database/sql/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

// name is the instrumentation name.
const name = "database/sql"

// IncludeDBStatementEnvVar is the environment variable to opt-in for sql query inclusion in the trace.
const IncludeDBStatementEnvVar = "OTEL_GO_AUTO_INCLUDE_DB_STATEMENT"
const (
// name is the instrumentation name.
name = "database/sql"
// pkg is the package being instrumented.
pkg = "database/sql"

// IncludeDBStatementEnvVar is the environment variable to opt-in for sql query inclusion in the trace.
IncludeDBStatementEnvVar = "OTEL_GO_AUTO_INCLUDE_DB_STATEMENT"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "database/sql",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.AllocationConst{},
Expand Down Expand Up @@ -158,7 +162,7 @@ func convertEvent(e *event) *probe.Event {
}

return &probe.Event{
Library: name,
Package: pkg,
Name: "DB",
Kind: trace.SpanKindClient,
StartTime: int64(e.StartTime),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestProbeConvertEvent(t *testing.T) {
TraceFlags: trace.FlagsSampled,
})
want := &probe.Event{
Library: name,
Package: pkg,
Name: "DB",
Kind: trace.SpanKindClient,
StartTime: int64(start.UnixNano()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

// name is the instrumentation name.
const name = "github.com/gin-gonic/gin"
const (
// name is the instrumentation name.
name = "github.com/gin-gonic/gin"
// pkg is the package being instrumented.
pkg = "github.com/gin-gonic/gin"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "github.com/gin-gonic/gin",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.StructFieldConst{
Expand Down Expand Up @@ -122,7 +126,7 @@ func convertEvent(e *event) *probe.Event {
})

return &probe.Event{
Library: name,
Package: pkg,
// Do not include the high-cardinality path here (there is no
// templatized path manifest to reference, given we are instrumenting
// Engine.ServeHTTP which is not passed a Gin Context).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestProbeConvertEvent(t *testing.T) {
TraceFlags: trace.FlagsSampled,
})
want := &probe.Event{
Library: name,
Package: pkg,
Name: "GET",
Kind: trace.SpanKindServer,
StartTime: int64(start.UnixNano()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

// name is the instrumentation name.
const name = "google.golang.org/grpc"
const (
// name is the instrumentation name.
name = "google.golang.org/grpc/client"
// pkg is the package being instrumented.
pkg = "google.golang.org/grpc"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "google.golang.org/grpc",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.AllocationConst{},
Expand Down Expand Up @@ -164,7 +168,7 @@ func convertEvent(e *event) *probe.Event {
}

return &probe.Event{
Library: name,
Package: pkg,
Name: method,
Kind: trace.SpanKindClient,
StartTime: int64(e.StartTime),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

// name is the instrumentation name.
const name = "google.golang.org/grpc/server"
const (
// name is the instrumentation name.
name = "google.golang.org/grpc/server"
// pkg is the package being instrumented.
pkg = "google.golang.org/grpc"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "google.golang.org/grpc",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.AllocationConst{},
Expand Down Expand Up @@ -152,7 +156,7 @@ func convertEvent(e *event) *probe.Event {
}

return &probe.Event{
Library: name,
Package: pkg,
Name: method,
Kind: trace.SpanKindServer,
StartTime: int64(e.StartTime),
Expand Down
11 changes: 8 additions & 3 deletions internal/pkg/instrumentation/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

const name = "net/http/client"
const (
// name is the instrumentation name.
name = "net/http/client"
// pkg is the package being instrumented.
pkg = "net/http"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "net/http",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.AllocationConst{},
Expand Down Expand Up @@ -143,7 +148,7 @@ func convertEvent(e *event) *probe.Event {
}

return &probe.Event{
Library: name,
Package: pkg,
Name: path,
Kind: trace.SpanKindClient,
StartTime: int64(e.StartTime),
Expand Down
11 changes: 8 additions & 3 deletions internal/pkg/instrumentation/bpf/net/http/server/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ import (

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64,arm64 -cc clang -cflags $CFLAGS bpf ./bpf/probe.bpf.c

const name = "net/http"
const (
// name is the instrumentation name.
name = "net/http/server"
// pkg is the package being instrumented.
pkg = "net/http"
)

// New returns a new [probe.Probe].
func New(logger logr.Logger) probe.Probe {
return &probe.Base[bpfObjects, event]{
Name: name,
Logger: logger.WithName(name),
InstrumentedPkg: "net/http",
InstrumentedPkg: pkg,
Consts: []probe.Const{
probe.RegistersABIConst{},
probe.StructFieldConst{
Expand Down Expand Up @@ -151,7 +156,7 @@ func convertEvent(e *event) *probe.Event {
}

return &probe.Event{
Library: name,
Package: pkg,
// Do not include the high-cardinality path here (there is no
// templatized path manifest to reference).
Name: method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestProbeConvertEvent(t *testing.T) {
TraceFlags: trace.FlagsSampled,
})
want := &probe.Event{
Library: name,
Package: pkg,
Name: "GET",
Kind: trace.SpanKindServer,
StartTime: int64(start.UnixNano()),
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/instrumentation/probe/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// Event is a telemetry event that happens within an instrumented package.
type Event struct {
Library string
Package string
Name string
Attributes []attribute.KeyValue
Kind trace.SpanKind
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/opentelemetry/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ type Controller struct {
bootTime int64
}

func (c *Controller) getTracer(libName string) trace.Tracer {
t, exists := c.tracersMap[libName]
func (c *Controller) getTracer(pkg string) trace.Tracer {
t, exists := c.tracersMap[pkg]
if exists {
return t
}

newTracer := c.tracerProvider.Tracer(
libName,
"go.opentelemetry.io/auto/"+pkg,
trace.WithInstrumentationVersion(c.version),
)
c.tracersMap[libName] = newTracer
c.tracersMap[pkg] = newTracer
return newTracer
}

Expand All @@ -65,7 +65,7 @@ func (c *Controller) Trace(event *probe.Event) {
}

ctx = ContextWithEBPFEvent(ctx, *event)
_, span := c.getTracer(event.Library).
_, span := c.getTracer(event.Package).
Start(ctx, event.Name,
trace.WithAttributes(event.Attributes...),
trace.WithSpanKind(event.Kind),
Expand Down
14 changes: 3 additions & 11 deletions internal/test/e2e/databasesql/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"scopeSpans": [
{
"scope": {
"name": "database/sql",
"name": "go.opentelemetry.io/auto/database/sql",
"version": "v0.8.0-alpha"
},
"spans": [
Expand All @@ -69,7 +69,7 @@
},
{
"scope": {
"name": "net/http",
"name": "go.opentelemetry.io/auto/net/http",
"version": "v0.8.0-alpha"
},
"spans": [
Expand Down Expand Up @@ -100,15 +100,7 @@
"spanId": "xxxxx",
"status": {},
"traceId": "xxxxx"
}
]
},
{
"scope": {
"name": "net/http/client",
"version": "v0.8.0-alpha"
},
"spans": [
},
{
"attributes": [
{
Expand Down
20 changes: 10 additions & 10 deletions internal/test/e2e/databasesql/verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

load ../../test_helpers/utilities

LIBRARY_NAME="database/sql"
SCOPE="go.opentelemetry.io/auto/database/sql"

@test "${LIBRARY_NAME} :: includes db.statement attribute" {
result=$(span_attributes_for ${LIBRARY_NAME} | jq "select(.key == \"db.statement\").value.stringValue")
@test "${SCOPE} :: includes db.statement attribute" {
result=$(span_attributes_for ${SCOPE} | jq "select(.key == \"db.statement\").value.stringValue")
assert_equal "$result" '"SELECT * FROM contacts"'
}

@test "${LIBRARY_NAME} :: trace ID present and valid in all spans" {
trace_id=$(spans_from_scope_named ${LIBRARY_NAME} | jq ".traceId")
@test "${SCOPE} :: trace ID present and valid in all spans" {
trace_id=$(spans_from_scope_named ${SCOPE} | jq ".traceId")
assert_regex "$trace_id" ${MATCH_A_TRACE_ID}
}

@test "${LIBRARY_NAME} :: span ID present and valid in all spans" {
span_id=$(spans_from_scope_named ${LIBRARY_NAME} | jq ".spanId")
@test "${SCOPE} :: span ID present and valid in all spans" {
span_id=$(spans_from_scope_named ${SCOPE} | jq ".spanId")
assert_regex "$span_id" ${MATCH_A_SPAN_ID}
}

@test "${LIBRARY_NAME} :: parent span ID present and valid in all spans" {
parent_span_id=$(spans_from_scope_named ${LIBRARY_NAME} | jq ".parentSpanId")
@test "${SCOPE} :: parent span ID present and valid in all spans" {
parent_span_id=$(spans_from_scope_named ${SCOPE} | jq ".parentSpanId")
assert_regex "$parent_span_id" ${MATCH_A_SPAN_ID}
}

@test "${LIBRARY_NAME} :: expected (redacted) trace output" {
@test "${SCOPE} :: expected (redacted) trace output" {
redact_json
assert_equal "$(git --no-pager diff ${BATS_TEST_DIRNAME}/traces.json)" ""
}
4 changes: 2 additions & 2 deletions internal/test/e2e/gin/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"scopeSpans": [
{
"scope": {
"name": "github.com/gin-gonic/gin",
"name": "go.opentelemetry.io/auto/github.com/gin-gonic/gin",
"version": "v0.8.0-alpha"
},
"spans": [
Expand Down Expand Up @@ -75,7 +75,7 @@
},
{
"scope": {
"name": "net/http/client",
"name": "go.opentelemetry.io/auto/net/http",
"version": "v0.8.0-alpha"
},
"spans": [
Expand Down
Loading
Loading