Skip to content

Commit

Permalink
Merge branch 'main' into flavien/service-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottness authored Nov 25, 2024
2 parents 3bc7912 + 58e1e63 commit c7063d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
5 changes: 1 addition & 4 deletions ddtrace/ddtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ type SpanContextW3C interface {
type SpanContextWithLinks interface {
SpanContext

// SpanLinks returns the span links on the SpanContext.
// SpanLinks returns a copy of the span links on the SpanContext.
SpanLinks() []SpanLink

// Setlinks takes in a slice of SpanLinks and sets them to the SpanContext.
SetLinks(links []SpanLink)
}

// Tracer specifies an implementation of the Datadog tracer which allows starting
Expand Down
10 changes: 4 additions & 6 deletions ddtrace/tracer/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ func TestStartSpanWithSpanLinks(t *testing.T) {
_, _, _, stop := startTestTracer(t)
defer stop()
spanLink := ddtrace.SpanLink{TraceID: 789, TraceIDHigh: 0, SpanID: 789, Attributes: map[string]string{"reason": "terminated_context", "context_headers": "datadog"}, Flags: 0}
var ctx ddtrace.SpanContext
ctx = &spanContext{spanID: 789, traceID: traceIDFrom64Bits(789), spanLinks: []ddtrace.SpanLink{spanLink}}
ctx := &spanContext{spanID: 789, traceID: traceIDFrom64Bits(789), spanLinks: []ddtrace.SpanLink{spanLink}}

t.Run("spanContext with spanLinks satisfies SpanContextWithLinks interface", func(t *testing.T) {
ctxLink, ok := ctx.(ddtrace.SpanContextWithLinks)
assert.True(t, ok)
assert.Equal(t, len(ctxLink.SpanLinks()), 1)
assert.Equal(t, ctxLink.SpanLinks()[0], spanLink)
var _ ddtrace.SpanContextWithLinks = ctx
assert.Equal(t, len(ctx.SpanLinks()), 1)
assert.Equal(t, ctx.SpanLinks()[0], spanLink)
})

t.Run("create span from spancontext with links", func(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions ddtrace/tracer/spancontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,11 @@ func (c *spanContext) TraceID128Bytes() [16]byte {
return c.traceID
}

// SpanLinks implements ddtrace.SpanContextWithLinks
func (c *spanContext) SpanLinks() []ddtrace.SpanLink {
return c.spanLinks
}

func (c *spanContext) SetLinks(links []ddtrace.SpanLink) {
c.spanLinks = links
cp := make([]ddtrace.SpanLink, len(c.spanLinks))
copy(cp, c.spanLinks)
return cp
}

// ForeachBaggageItem implements ddtrace.SpanContext.
Expand Down
12 changes: 6 additions & 6 deletions internal/civisibility/integrations/gotesting/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ func getInstrumentationMetadata(fn *runtime.Func) *instrumentationMetadata {

// setInstrumentationMetadata stores an instrumentation metadata for a given *runtime.Func.
func setInstrumentationMetadata(fn *runtime.Func, metadata *instrumentationMetadata) {
instrumentationMapMutex.RLock()
defer instrumentationMapMutex.RUnlock()
instrumentationMapMutex.Lock()
defer instrumentationMapMutex.Unlock()
instrumentationMap[fn] = metadata
}

// createTestMetadata creates the CI visibility test metadata associated with a given *testing.T, *testing.B, *testing.common
func createTestMetadata(tb testing.TB) *testExecutionMetadata {
ciVisibilityTestMetadataMutex.RLock()
defer ciVisibilityTestMetadataMutex.RUnlock()
ciVisibilityTestMetadataMutex.Lock()
defer ciVisibilityTestMetadataMutex.Unlock()
execMetadata := &testExecutionMetadata{}
ciVisibilityTestMetadata[reflect.ValueOf(tb).UnsafePointer()] = execMetadata
return execMetadata
Expand All @@ -135,8 +135,8 @@ func getTestMetadataFromPointer(ptr unsafe.Pointer) *testExecutionMetadata {

// deleteTestMetadata delete the CI visibility test metadata associated with a given *testing.T, *testing.B, *testing.common
func deleteTestMetadata(tb testing.TB) {
ciVisibilityTestMetadataMutex.RLock()
defer ciVisibilityTestMetadataMutex.RUnlock()
ciVisibilityTestMetadataMutex.Lock()
defer ciVisibilityTestMetadataMutex.Unlock()
delete(ciVisibilityTestMetadata, reflect.ValueOf(tb).UnsafePointer())
}

Expand Down

0 comments on commit c7063d8

Please sign in to comment.