Skip to content

Commit

Permalink
fix(tracing): set service version (#290)
Browse files Browse the repository at this point in the history
We were previously only setting the lambda "version" in our
instrumentation version. In practice this instrumentation is only
present in our cold start trace (`realInit`). Other traces will use
tracers belonging to different instrumentation libraries.

This commit introduces `service.version` as part of the resource
attributes. Since the binary is rebuilt on cloudformation template
changes, it should accurately track the version of the service rather
than merely the "binary" version.
  • Loading branch information
jta committed May 31, 2024
1 parent 8a6fcbc commit 4871ad4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import (
"net/url"
"os"

"github.com/observeinc/aws-sam-apps/version"

"github.com/go-logr/logr"
"go.opentelemetry.io/contrib/detectors/aws/lambda"
"go.opentelemetry.io/contrib/exporters/autoexport"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
)

var serviceVersionKey = attribute.Key("service.version")

func SetLogger(logger logr.Logger) {
otel.SetLogger(logger)
}
Expand Down Expand Up @@ -51,6 +56,7 @@ func NewTracerProvider(ctx context.Context) (*trace.TracerProvider, error) {
}

options := []resource.Option{
resource.WithAttributes(serviceVersionKey.String(version.Version)),
resource.WithFromEnv(),
}
if os.Getenv("AWS_LAMBDA_FUNCTION_NAME") != "" {
Expand Down

0 comments on commit 4871ad4

Please sign in to comment.