Skip to content

Commit 0a65e26

Browse files
committed
fix: Add additional tests for v2 and squash some bugs
- Added additional test cases Fixes: - Added missing setting of DisableUpdateTracing for `Options()` - Add safe type safe assertions to avoid panics - Fix temporal. prefix setting
1 parent 39d173f commit 0a65e26

File tree

2 files changed

+753
-5
lines changed

2 files changed

+753
-5
lines changed

contrib/datadog/v2/tracing/interceptor.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (t *tracerImpl) Options() interceptor.TracerOptions {
8484
HeaderKey: headerKey,
8585
DisableSignalTracing: t.opts.DisableSignalTracing,
8686
DisableQueryTracing: t.opts.DisableQueryTracing,
87+
DisableUpdateTracing: t.opts.DisableUpdateTracing,
8788
}
8889
}
8990

@@ -103,7 +104,12 @@ func (t *tracerImpl) UnmarshalSpan(m map[string]string) (interceptor.TracerSpanR
103104

104105
func (t *tracerImpl) MarshalSpan(span interceptor.TracerSpan) (map[string]string, error) {
105106
carrier := tracer.TextMapCarrier{}
106-
if err := tracer.Inject(span.(*tracerSpan).Context(), carrier); err != nil {
107+
tSpan, ok := span.(*tracerSpan)
108+
if !ok {
109+
return nil, fmt.Errorf("expected *tracerSpan, got %T", span)
110+
}
111+
112+
if err := tracer.Inject(tSpan.Context(), carrier); err != nil {
107113
return nil, err
108114
}
109115
return carrier, nil
@@ -118,7 +124,11 @@ func (t *tracerImpl) SpanFromContext(ctx context.Context) interceptor.TracerSpan
118124
}
119125

120126
func (t *tracerImpl) ContextWithSpan(ctx context.Context, span interceptor.TracerSpan) context.Context {
121-
return tracer.ContextWithSpan(ctx, span.(*tracerSpan).Span)
127+
tSpan, ok := span.(*tracerSpan)
128+
if !ok {
129+
return ctx
130+
}
131+
return tracer.ContextWithSpan(ctx, tSpan.Span)
122132
}
123133

124134
// SpanFromWorkflowContext extracts the DataDog Span object from the workflow context.
@@ -147,7 +157,7 @@ func (t *tracerImpl) StartSpan(options *interceptor.TracerStartSpanOptions) (int
147157
tracer.ResourceName(options.Name),
148158
tracer.StartTime(options.Time),
149159
}
150-
// Set a deterministic span ID for workflows which are long-running and cross process boundaries
160+
// Set a deterministic span ID for workflows which are long-running and cross-process boundaries
151161
if options.IdempotencyKey != "" {
152162
startOpts = append(startOpts, tracer.WithSpanID(genSpanID(options.IdempotencyKey)))
153163
}
@@ -165,7 +175,7 @@ func (t *tracerImpl) StartSpan(options *interceptor.TracerStartSpanOptions) (int
165175
case *tracerSpanCtx:
166176
parentCtx = opParent.SpanContext
167177
default:
168-
// This should be considered an error, because something unexpected is
178+
// This should be considered an error because something unexpected is
169179
// in the place where only a parent trace should be. In this case, we don't
170180
// set up the parent, so we will be creating a new top-level span
171181
}
@@ -174,7 +184,7 @@ func (t *tracerImpl) StartSpan(options *interceptor.TracerStartSpanOptions) (int
174184
for k, v := range options.Tags {
175185
// TODO when custom span support is added we might have to revisit this
176186
// Display Temporal tags in a nested group in Datadog APM
177-
tagKey := "temporal." + strings.TrimPrefix(k, "temporal")
187+
tagKey := "temporal." + strings.TrimPrefix(k, "temporal.")
178188
startOpts = append(startOpts, tracer.Tag(tagKey, v))
179189
}
180190

0 commit comments

Comments
 (0)