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

[FEATURE REQ] ServiceBus receiver is not traced #26269

Closed
vyhid opened this issue Jan 5, 2022 · 4 comments · Fixed by #30508
Closed

[FEATURE REQ] ServiceBus receiver is not traced #26269

vyhid opened this issue Jan 5, 2022 · 4 comments · Fixed by #30508
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Service Bus
Milestone

Comments

@vyhid
Copy link

vyhid commented Jan 5, 2022

Query/Question
I use Service Bus in my project and when tried to instrument my code with OpenTelemetry noticed that context is not propagated when an async client is used. So I tried to look at the code and noticed that ServiceBusReceiverAsyncClient has TracerProvider but it's unused. Is this intentional for some reason or a bug?

Why is this not a Bug or a feature Request?
It might be a bug but it's easier to reference it from the code perspective

Setup (please complete the following information if applicable):

  • OS: Windows
  • IDE: e.g. IntelliJ
  • Library/Libraries: com.azure:azure-messaging-servicebus:7.5.0
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 5, 2022
@joshfree joshfree changed the title [QUERY] ServiceBus tracing doesn't work with OpenTelemetry Jan 10, 2022
@joshfree joshfree added Client This issue points to a problem in the data-plane of the library. Service Bus labels Jan 10, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jan 10, 2022
@joshfree
Copy link
Member

@lmolkova could you please follow up?

@lmolkova
Copy link
Member

lmolkova commented Jan 10, 2022

@vyhid thanks for reporting it!

Did you follow https://docs.microsoft.com/en-us/azure/developer/java/sdk/tracing to enable Azure SDK tracing ?

Can you please provide a small repro app? I'm specifically interested in

  • whether you use opentelemetry agent or Azure Monitor agent?
  • otherwise:

@vyhid
Copy link
Author

vyhid commented Jan 11, 2022

@lmolkova

here is the simple app: https://github.com/vyhid/sb-otel-instrumentation
I use the OpenTelemetry agent with Tracing Azure SDK https://docs.microsoft.com/en-us/azure/developer/java/sdk/tracing#tracing-azure-sdk-calls-with-opentelemetry-agent-of-sdk-preview
and I don't pass context directly

@lmolkova
Copy link
Member

lmolkova commented Feb 7, 2022

@vyhid I'm sorry it took me so long to get back to you. Thanks for providing the repro app!

So the problem is that we don't yet instrument receive call - we only instrument ServiceBus Processor, hence you never see anything from receiver and context is not propagated.

Do I understand correctly you don't use processor?

If so, can I suggest some manual steps that can help to instrument receive operation?
Here's the code:

  1. set up tracer and context extractor
private final static Tracer TRACER = GlobalOpenTelemetry.getTracer("app");

private static final Iterable<String> KEYS = List.of(com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY);
private static final TextMapGetter<ServiceBusReceivedMessage> SERVICE_BUS_CONTEXT_GETTER =
        new TextMapGetter<ServiceBusReceivedMessage>() {
            @Override
            public Iterable<String> keys(ServiceBusReceivedMessage carrier) {
                return KEYS;
            }

            @Override
            public String get(ServiceBusReceivedMessage carrier, String key) {
                if ("traceparent".equals(key)) {
                    Object value = carrier.getApplicationProperties().get(com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY);
                    return value == null ? null : value.toString();
                }

                return null;
            }
        };
  1. and then in your accept method, start a span using remote context from sender
   private static void accept(ServiceBusReceivedMessage msg) {
        Context remoteContext = W3CTraceContextPropagator.getInstance().extract(Context.current(), msg, SERVICE_BUS_CONTEXT_GETTER);

        Span span = TRACER.spanBuilder("ServiceBus.process").setParent(remoteContext).setSpanKind(SpanKind.CONSUMER).startSpan();
        try (Scope scope = Context.current().with(span).makeCurrent()) {
            System.out.println("msg.body : " + msg.getBody());
            System.out.println("msg.properties : " + msg.getApplicationProperties());
            doSomeJob();
            System.out.println("trace-id: " + span.getSpanContext().getTraceId());
            span.setStatus(StatusCode.OK);
        } catch (Throwable t) {
            span.recordException(t);
            span.setStatus(StatusCode.ERROR);
        } finally {
            span.end();
        }
    }

Here's what I see. And of course, you can add any attributes to the new span as you see fit.

image

I also sent PR to your repro app with suggested changes vyhid/sb-otel-instrumentation#1

I'll keep this bug open as a feature request to instrument receive calls (which we'll do once otel conventions around it will stabilize)

@lmolkova lmolkova changed the title ServiceBus tracing doesn't work with OpenTelemetry [Feature request] ServiceBus receiver is not traced Feb 7, 2022
@lmolkova lmolkova added the feature-request This issue requires a new behavior in the product in order be resolved. label Feb 7, 2022
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Feb 7, 2022
@lmolkova lmolkova removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Feb 7, 2022
@anuchandy anuchandy changed the title [Feature request] ServiceBus receiver is not traced [FEATURE REQ] ServiceBus receiver is not traced Apr 26, 2022
@jsquire jsquire added this to the Backlog milestone Jun 30, 2022
@jsquire jsquire moved this from Planned to Needs Costing in Azure SDK for Service Bus Jun 30, 2022
Repository owner moved this from Needs Costing to Done in Azure SDK for Service Bus Sep 26, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Service Bus
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants