-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[QUERY] Application Insights dependency auto-collection support for Azure.Messaging.ServiceBus #17940
Comments
Thank you for your feedback. Tagging and routing to the team member best able to assist. |
@pakrym - If you have any thoughts here, would you be so kind as to share them? |
Just to add that I've found removing Microsoft.ApplicationInsights.WorkerService 2.16.0 from my project allowed the dependency auto-collection support to start working with Azure.Messaging.ServiceBus 7.0.1 so there seems to be an incompatibility of some kind there. |
@JoshLove-msft @pakrym Any updates here? If this is a valid feature request or a bug, can you please add the appropriate label and milestone? |
Basically, everything is already done in Azure.Messaging.ServiceBus.Diagnostics. The only thing left to do is to add a dependency tracker to add additional data. In our setup, using Microsoft.ApplicationInsights.WorkerService we do get events posted to insights as "Request" but the operation name is "ServiceBusProcessor.ProcessMessage" and the target/source is not added as a metric so we can't really figure out what is the entity in question. We guess it based on the operations in the transaction :) Also worth noting that admin operations (e.g. create topic) are also added, their type is properly identified as "Azure Service Bus" which is because they are HTTP operations (XML API) which the library knows to identify as azure service bus operation. I guess this is left over from the old library where it had the same admin api. I believe some minor tweaks are required to fully support this library, as the |
We are adding an attribute that has the entity name - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/src/Diagnostics/DiagnosticProperty.cs#L19 Are you not seeing this? |
Possibly related - microsoft/ApplicationInsights-dotnet#2151 |
@JoshLove-msft While it's in the |
@pakrym @lmolkova do you have any insight here into what we are missing from the SDK side? |
Yes, ApplicationInsights SDK does not support collecting Track2 ServiceBus signals and needs a bit of work. It supports Track1 SDK though. I'm planning it for the next semester (first half of 2022). |
@lmolkova The library is great, but maybe providing some hooking points to certain modules will allow users to opt-in before official support it available. The 7.x versions are here for quite long. It will also allow users to add additional data, where need, instead of writing custom events. |
@shlomiassaf unfortunately there are no preview bits you could try. As you mentioned, we'd need something very similar to AzureSdkDiagnosticsEventHandler that takes care of creating requests/dependencies and setting all properties similar to EventHubs. If by any means you could contribute it to the Application Insights codebase earlier than next year, I can review it and work with the Application Insights team to get it merged. |
For anyone who tackles this, here's a quick workaround until this is fixed: Create (and register) an public class ServiceBusTelemetryInitializer : ITelemetryInitializer
{
public const string AzureServiceBus = "Azure Service Bus";
public ServiceBusTelemetryInitializer()
{
}
public void Initialize(ITelemetry telemetry)
{
try
{
if (Activity.Current != null) // Is this possible in an initializer???
{
if (telemetry is RequestTelemetry req &&
(req.Name == "ServiceBusProcessor.ProcessMessage" || req.Name == "ServiceBusSessionProcessor.ProcessSessionMessage"))
{
var entity = Activity.Current.Tags
.FirstOrDefault(t => t.Key == "message_bus.destination").Value;
var endpoint = Activity.Current.Tags
.FirstOrDefault(t => t.Key == "peer.address").Value;
req.Properties["Type"] = AzureServiceBus;
req.Context.Operation.Name = entity;
req.Source = string
.Format(CultureInfo.InvariantCulture, "type:{0} | entity:{1} | endpoint:{2}", AzureServiceBus, entity, endpoint);
}
else if (telemetry is DependencyTelemetry {Name: "ServiceBusSender.Send"} send)
{
var entity = Activity.Current.Tags
.FirstOrDefault(t => t.Key == "message_bus.destination").Value;
var endpoint = Activity.Current.Tags
.FirstOrDefault(t => t.Key == "peer.address").Value;
send.Type = AzureServiceBus;
send.Context.Operation.Name = entity;
send.Target = string.Join(" | ", endpoint, entity);
}
}
}
catch
{
// ignore
}
}
} The only issue is duplicated events On each send there are 2 events:
For each processor received message there are 2 events:
The "Receive" is not only when receiving, it's every polling timeout as well, I see a lot of 1 minute hits. For that you can use a processor: public class ServiceBusTelemetryProcessor : ITelemetryProcessor
{
private ITelemetryProcessor Next { get; }
// next will point to the next TelemetryProcessor in the chain.
public ServiceBusTelemetryProcessor(ITelemetryProcessor next) => Next = next;
public void Process(ITelemetry item)
{
if (item is RequestTelemetry {Name: "ServiceBusReceiver.Receive"})
return;
if (item is DependencyTelemetry {Name: "Message"})
return;
Next.Process(item);
}
} |
@lmolkova Hi there, any updates ? 🙂 |
Well, this explains why I have one service showing these 3 new dependencies. Thanks! We're using NServicebus and I've already wired up full tracing. Is there something about these dependencies that I could leverage instead, or should I write another filter to ignore these 3? ServiceBusReceiver.Receive, Message, and ServiceBusSender.Send |
The AppInsights update is available in https://www.nuget.org/packages/Microsoft.ApplicationInsights/2.21.0. The Functions integration will light up once Azure/azure-webjobs-sdk#2900 is addressed. |
Query/Question
I am using Azure.Messaging.ServiceBus with a new Azure Function integrated with Application Insights. Should the Service Bus be automatically detected as a dependency by Application Insights and show up in the Application Map? It isn't listed as supported at Dependency auto-collection so I'm assuming not? If this is the case, is there a plan for this to be implemented in the future or documentation on how to manually set up the dependency collection with the current version?
Environment:
The text was updated successfully, but these errors were encountered: