8000 [FSSDK-9862] Add OpenTelemetry Tracing support by pulak-opti · Pull Request #385 · optimizely/go-sdk · GitHub
[go: up one dir, main page]

Skip to content

[FSSDK-9862] Add OpenTelemetry Tracing support #385

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

Merged
merged 21 commits into from
Jan 18, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add comment
  • Loading branch information
pulak-opti committed Jan 9, 2024
commit a8c4354420b76d6333e1dc0e79c8188e33e1a6d0
44 changes: 25 additions & 19 deletions pkg/tracing/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,20 @@ import (
"go.opentelemetry.io/otel/trace"
)

// Tracer provides the necessary method to collect telemetry trace data.
// Tracer should not depend on any specific tool. To make it possible it returns a Span interface.
type Tracer interface {
// StartSpan starts a trace span. Span can be a parent or child span based on the passed context.
StartSpan(ctx context.Context, tracerName, spanName string) (context.Context, Span)
}

// Span interface implements the trace span returned by Tracer.
type Span interface {
End()
SetAttibutes(key string, value interface{})
}

type otelSpan struct {
span trace.Span
}

func (s *otelSpan) SetAttibutes(key string, value interface{}) {
s.span.SetAttributes(attribute.KeyValue{
Key: attribute.Key(key),
Value: attribute.StringValue(value.(string)),
})
}

func (s *otelSpan) End() {
s.span.End()
}

type Tracer interface {
StartSpan(ctx context.Context, tracerName, spanName string) (context.Context, Span)
}

// otelTracer is an OpenTelemetry implementation of Tracer
type otelTracer struct {
enabled bool
}
Expand All @@ -49,6 +39,22 @@ func (t *otelTracer) StartSpan(pctx context.Context, tracerName, spanName string
}
}

// otelSpan is an OpenTelemetry Span implementation of Span
type otelSpan struct {
span trace.Span
}

func (s *otelSpan) SetAttibutes(key string, value interface{}) {
s.span.SetAttributes(attribute.KeyValue{
Key: attribute.Key(key),
Value: attribute.StringValue(value.(string)),
})
}

func (s *otelSpan) End() {
s.span.End()
}

type NoopTracer struct{}

func (t *NoopTracer) StartSpan(ctx context.Context, tracerName string, spanName string) (context.Context, Span) {
Expand Down
0