Skip to content
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

apmotel: native transaction are always considered non-recording when retrieved from Otel's trace.SpanFromContext #1476

Closed
wzy9607 opened this issue Jun 28, 2023 · 0 comments · Fixed by #1478
Labels

Comments

@wzy9607
Copy link

wzy9607 commented Jun 28, 2023

Describe the bug

After started a apm transaction, apm.TransactionFromContext(ctx).Sampled() and Otel's trace.SpanFromContext(ctx).IsRecording() returns different result.
the later is always false.

To Reproduce

package main

import (
	"context"
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
	"go.elastic.co/apm/module/apmotel/v2"
	"go.elastic.co/apm/v2"
	"go.elastic.co/apm/v2/apmtest"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/trace"
)

func Test_a(t *testing.T) {
	t.Parallel()
	tracer := apmtest.NewRecordingTracer()
	provider, err := apmotel.NewTracerProvider(apmotel.WithAPMTracer(tracer.Tracer))
	if err != nil {
		panic(err)
	}
	otel.SetTracerProvider(provider)

	ctx := context.Background()
	tx := tracer.StartTransaction("test1", "test")
	ctx = apm.ContextWithTransaction(ctx, tx)

	tx = apm.TransactionFromContext(ctx)
	sp := trace.SpanFromContext(ctx)
	fmt.Printf("apm transaction: %#v\n", tx)
	fmt.Printf("OTel span: %#v\n", sp)
	assert.Equal(t, tx.Sampled(), sp.IsRecording())
}

Expected behavior

Expect the assert to not fail.

@wzy9607 wzy9607 changed the title apmotel: native transaction are always not recording when obtained from Otel's trace.SpanFromContext apmotel: native transaction are always considered non-recording when obtained from Otel's trace.SpanFromContext Jun 28, 2023
@wzy9607 wzy9607 changed the title apmotel: native transaction are always considered non-recording when obtained from Otel's trace.SpanFromContext apmotel: native transaction are always considered non-recording when retrieved from Otel's trace.SpanFromContext Jun 28, 2023
@dmathieu dmathieu linked a pull request Jun 28, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant