Closed
Description
openedon 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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment