question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Application Insights -- add custom dimensions to 'requests' telemetry items generated by the host

See original GitHub issue

Hi,

I’m really missing the ability to decorate each request with custom dimensions. I’m using the native functions integration with AppInsights, and I use ILogger – I wouldn’t want to install the AppInsights nuget and do all the initializations myself.

Optimal solution for me is to have a Dictionary as an optional input in the Function’s signature.

Is this by any chance possible today? If not, can you consider this as a new feature/improvement?

Many thanks ! Jonathan

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
xstofcommented, Nov 29, 2019

Activity.Current.Tag(…) seems to work and translates into a custom property on the App Insights side. Would be good to have confirmation this is a supported way of working. Similarly, Activity.Current.AddBagage equally seems to work for custom tracking data which you want to pass onto any dependencies (and dependencies of those… all the way down)l. This is compatible with at least Service Bus and .NET Core Http.

2reactions
rjkcommented, Mar 3, 2022

The code from @mheskandari works for me to add to traces table, but that doesn’t include it in requests table. This makes sense: logs written from ILogger just go to traces table.

To add to customDimensions within the requests table you can do this:

httpContext.Features.Get<RequestTelemetry>().Properties["SomePropertyName"] = someData;

e.g. as described here in more detail https://www.davepaquette.com/archive/2020/03/07/enhancing-application-insights-request-telemetry.aspx

@xstof suggests above that you could instead use System.Diagnostics.Activity.Current.AddTag() to add custom dimensions to requests but that doesn’t work for me now (Application Insights v2.19.0). The tags don’t seem to go anywhere. Seems like it would be nice, perhaps I’m just doing it wrong.

If you want to add custom properties that are automatically added to dependencies (e.g. SQL) and traces tables you can use System.Diagnostics.Activity.Current.AddBaggage(), e.g. within a middleware class so this gets done at the start of every request. In my testing this does not get added to requests table though, so I need to do both this and the RequestTelemetry Properties as above.

string theTenantId = // get something from httpContext
System.Diagnostics.Activity.Current.AddBaggage("MyTenantId", theTenantId);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding Custom Dimension to Request Telemetry - Azure ...
1.In Visual studio, create a function app(In my test, I create a blob triggerd function), and install the following nuget packages: Microsoft.
Read more >
Application Insights telemetry data model - Azure Monitor
Custom measurements are associated with the telemetry item they belong to. They're subject to sampling with the telemetry item that contains ...
Read more >
Analyze Azure Functions telemetry in Application Insights
Learn how to view and query for Azure Functions telemetry data collected by and stored in Azure Application Insights.
Read more >
How to use Application Insights Custom Properties in ...
Azure Application Insights is great for easily adding telemetry to ... to select all items where the FirstName custom dimension is “Cat”, ...
Read more >
Azure Application Insights — How not to burn money using it
In this blog post, I'm going to talk about Azure Application Insights and how I learned not to take certain things for granted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found