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

apm.TransactionFromContext always nil #1637

Closed
ga845937 opened this issue Jul 23, 2024 · 1 comment
Closed

apm.TransactionFromContext always nil #1637

ga845937 opened this issue Jul 23, 2024 · 1 comment
Labels

Comments

@ga845937
Copy link

ga845937 commented Jul 23, 2024

Describe the bug
I am using a combination of:
go.elastic.co/apm v1.15.0
go.elastic.co/apm/module/apmgin/v2 v2.6.0
go.elastic.co/apm/module/apmsql/v2 v2.6.0

apmgin and apmsql work
image

To Reproduce
Steps to reproduce the behavior:

gin middleware setting

engine := gin.New()
engine.Use(apmgin.Middleware(engine), middleware.Logger())

I try to get TraceID in middleware.Logger(),
Elastic Docs module/apmgin say [ For each request, a transaction is stored in the request context, which can be obtained via gin.Context.Request.Context() in your handler. ]

so in middleware.Logger()

var traceID string
tx := apm.TransactionFromContext(context.Request.Context())
if tx != nil {
    traceID = tx.TraceContext().Trace.String()
}

logger.Info( "request",
    zap.String("traceID", traceID),
    .... other field
)

tx always nil, so traceID always ""

Expected behavior
get the traceID

@axw
Copy link
Member

axw commented Jul 24, 2024

I am using a combination of:
go.elastic.co/apm v1.15.0
go.elastic.co/apm/module/apmgin/v2 v2.6.0
go.elastic.co/apm/module/apmsql/v2 v2.6.0

Using a combination of v1 and v2 is not going to work - you will need to update from apm to apm/v2.

@axw axw closed this as completed Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants