-
Notifications
You must be signed in to change notification settings - Fork 368
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
Establish a trace context in a non-http context #9856
Comments
I'll try to reply tomorrow at some point, else on Friday. |
Ok, if I understand your question correctly you need to look at docs on Establishing traces on non HTTP requests when you want to trace your ActiveMq activity (know that I'm not at all familiar with ActiveMq). So, integrating the code example from that link into your code, ir could look something like this: private void Consume(IMessage message)
{
using var scope = _sp.CreateScope();
EstablishTrace(scope, message);
var logger = scope.ServiceProvider.GetRequiredService<ILogger<ActiveMQConsumer>>();
var txtMessage = message as ITextMessage ?? throw new IllegalStateException("not an ITextMessage, impossible !!!");
logger.LogInformation("received ActiveMQ message {}", txtMessage.Text);
}
private void EstablishTrace(IServiceScope scope, IMessage message)
{
ITraceContext traceContext = GetTraceContextFromIncomingMessage(message);
var tracerFactory = scope.GetRequiredService<Func<ITraceContext, IManagedTracer>>();
IManagedTracer tracer = tracerFactory(traceContext);
ContextTracerManager.SetCurrentTracer(tracer);
}
private ITraceContext GetTraceContextFromIncomingMessage(IMessage message)
{
// You need to extract the trace context from the incoming message and create
// an instance of ITraceContext (you can use Google.Cloud.Diagnostics.Common.SimpleTraceContext).
// If the incoming message does not contain a trace context, you can create a new one by creating a new
// trace ID.
} Let me know if this helps. |
I tried the solution and now I do not see logs anymore on GCP 😒 However, I did fallback to Console.WriteLine and I do not see that either, meaning the server is simply not pulling messsages anymore so I really have another problem somewhere 😱 I've yet to find some time to understand what is going on before bothering you, but be assured that I will report back here as soon as possible 😄 Anyway, the code I added is the following :
|
OK, let me know when you know more and I can help then. |
@christopheblin I'll be closing this one until you are ready to provide more information, and that now seems to depend on #9948 . Happy to reopen as soon as you are ready. |
I've seen #5897 and #9157 and #9476 and https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore3/latest#custom-trace-context-example
However, after multiple tries, I'm not able to wrap my head around ITraceContext when I want both the "default" context (i.e for HTTP context) and my own context for non-http context, so I'm asking for help here...
Basically, I have a cloud run with an HTTP API where the default "integration" is OK (i.e when I do _logger.LogInformation("xxx"), i can see this log statement when I do "Show logs for the trace" from logs explorer)
Now, this cloud run also connects to ActiveMq, and I do not manage to create a new trace for each message received
Here is where I am stuck :
I can provide details about what I've tried if necessary
The text was updated successfully, but these errors were encountered: