Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.63k stars 4.85k forks source link

[BUG] ServiceBus: don't report Receive activity when SB processor is used #47985

Open lmolkova opened 1 week ago

lmolkova commented 1 week ago

Library name and version

Azure.Messaging.ServiceBus 7.18.3

Describe the bug

I use processor client and enable tracing. I expect to have Process and settlement activities, but not receive one since I don't initiate the receive operation in the user code.

But I see both - receive and process ones. Also I see receive operations for poll which my app didn't initiate either

Expected behavior

When processor client is used, we should not report any of the receive activities initiated by processor.

Actual behavior

Image

Reproduction Steps

using Azure.Messaging.ServiceBus;
using Azure.Identity;
using OpenTelemetry.Trace;

AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
    .WithTracing(tp => tp
    .SetSampler(new AlwaysOnSampler())
    .AddSource("*")
    .AddAspNetCoreInstrumentation()
    .AddOtlpExporter());

var sbClient = new ServiceBusClient("lm-tests.servicebus.windows.net", new DefaultAzureCredential());
var sbSender = sbClient.CreateSender("testme");
var sbProcessor = sbClient.CreateProcessor("testme");

sbProcessor.ProcessMessageAsync += m =>
{
    Console.WriteLine($"processing {m.Message} {m.Message.ApplicationProperties.GetValueOrDefault("traceparent", null)}");
    return Task.CompletedTask;
};

sbProcessor.ProcessErrorAsync += e => Task.CompletedTask;

var app = builder.Build();
app.MapGet("/send", () =>
{
    return sbSender.SendMessageAsync(new ServiceBusMessage("hi!"));
});

await sbProcessor.StartProcessingAsync();
app.Run();
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>servicebus_dotnet</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.13.2" />
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.3" />
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.1" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.1" />
    <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
  </ItemGroup>

</Project>

Environment

Original report: https://bsky.app/profile/martindotnet.bsky.social/post/3lgkyf7pr2227

github-actions[bot] commented 1 week ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.