Skip to content

Commit

Permalink
feat: add application version
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Apr 17, 2024
1 parent f0bcd0b commit 6abb916
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions analyticsx/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

type AppInfo struct {
Name string
Name string
Version string
}

func NewAnalytics(ctx context.Context, app AppInfo) (*sdktrace.TracerProvider, error) {
return otelx.InitTracerProvider(ctx, app.Name, otlptracehttp.WithEndpointURL("https://telemetry.cerberauth.com"))
return otelx.InitTracerProvider(ctx, app.Name, app.Version, otlptracehttp.WithEndpointURL("https://telemetry.cerberauth.com"))
}
7 changes: 4 additions & 3 deletions otelx/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ var (
initResourcesOnce sync.Once
)

func InitResource(serviceName string) *sdkresource.Resource {
func InitResource(serviceName string, version string) *sdkresource.Resource {
initResourcesOnce.Do(func() {
extraResources, _ := sdkresource.New(
context.Background(),
sdkresource.WithOS(),
sdkresource.WithAttributes(
semconv.ServiceName(serviceName),
semconv.ServiceVersion(version),
),
)
resource, _ = sdkresource.Merge(
Expand All @@ -33,14 +34,14 @@ func InitResource(serviceName string) *sdkresource.Resource {
return resource
}

func InitTracerProvider(ctx context.Context, serviceName string, opts ...otlptracehttp.Option) (*sdktrace.TracerProvider, error) {
func InitTracerProvider(ctx context.Context, serviceName string, version string, opts ...otlptracehttp.Option) (*sdktrace.TracerProvider, error) {
exporter, err := otlptracehttp.New(ctx, opts...)
if err != nil {
return nil, err
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithSyncer(exporter),
sdktrace.WithResource(InitResource(serviceName)),
sdktrace.WithResource(InitResource(serviceName, version)),
)
otel.SetTracerProvider(tp)
return tp, nil
Expand Down

0 comments on commit 6abb916

Please sign in to comment.