ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

Add `customSpan` telemetry type

Open johncrim opened this issue 2 years ago • 3 comments

Problem description

We need a telemetry type that is similar to customEvent, but that has an id and a duration (and probably a success: boolean). In other words, something that maps directly to a span in OpenTelemetry.

We need this to model a number of operations in our telemetry, where an operation has a start, and an end, and an optional parent operation. For example, steps in a wizard, or long-running batch data operations.

Today, the telemetry types pageView, request, and dependency all represent spans (and also have more specific meaning), and as such they can be linked in the app insights transaction tree. However, there is no telemetry object that represents a generic span, and that's what I'm looking for.

customEvent is nice in that it represents any custom telemetry that a user needs - but it doesn't provide semantics for spans. Also, customEvent has itemCount, which doesn't belong in spans.

Describe the solution you'd like

A new custom telemetry type that provides span fields, as described above. Objects of this type should be displayed as nodes in the transaction search tree.

Describe alternatives you've considered

Today we use the customEvent telemetry type for custom spans; but we have to stick the duration and spanId values in properties, and do our own querying and rendering to patch up the graph of spans.

johncrim avatar Dec 21 '23 00:12 johncrim

Are you looking for this in the JS SDK?

As we don't enforce any itemCount (or anything really except the name) for a custom event (sent via trackEvent),

We already have support for "updating the traceid / spanid via the appInsights.getTraceCtx and you can also set the full context via the appInsights.setTraceCtx. So you could update either the entire trace/span/flags ids or the individual items

We effectively "manage" this for the entire SDK instance (so in OpenTelemetry parlance, we only have 1 parent Span (using the same traceId). With the only "real" child spans being the Ajax RemoteDependency items

Part of the request also seems to be requesting updates to the Azure Monitor UX (which this team doesn't own), please let me know if I'm reading the request correctly and if so I can send a request (this issue really) onto the UX team to add to their task list (if they don't have it listed already), as other languages (node, java, python) already directly use the versions of OpenTelemetry -- we don't for the web partially because of the size of the OT packages.

MSNev avatar Dec 21 '23 00:12 MSNev

Hi @MSNev - thank you for the reply.

You're correct, I'm looking for more than would be included in the JS SDK - I opened this here because I'm not aware of a github repo that encompasses everything, and I don't think there's a github repo for the Azure Monitor UX. I would be happy to move this to a better repo if there is such a place.

The full solution would include:

  • Expansion of the "standard" application insights telemetry types in Azure to support custom Spans. This would benefit SDKs for all programming languages. The options are either:
    • Add id, duration, and success to customEvent, or..
    • Create a new custom telemetry type with otel Span semantics - I like the name customSpan
  • Azure App Insights UX support for viewing that telemetry type in the transaction tree (aka otel Trace graph)
  • JS SDK support for tracking this telemetry type (either new fields in trackEvent(), or trackSpan({...}))

I currently do use the getTraceCtx and similar APIs in the JS SDK to make sure the telemetry items are linked appropriately. Right now I can have a customEvent that is a child of a telemetry object with Span semantics (eg pageView or dependency). However I can't make another telemetry item a child of customEvent - eg a trace or dependency should be able to be a child of a custom span. Does that make sense?

I can certainly do these things kind of just using properties (right now I stick the spanId in a customEvent property), but since it's not a standard part of the data model it's never going to be useable in standard tools - so we'd have to write our own.

We also use the app insights .NET SDK. A telemetry type that is not strongly tied to a specific interaction (like pageView, dependency, request), with otel Span semantics, would also be useful in .NET, and all other app insights SDKs.

johncrim avatar Dec 22 '23 23:12 johncrim

I'm not aware of the location (this repo isn't the location), but I've sent an internal request to try and find the correct path to have this logged / prioritized. However, due to holidays the necessary people are currently away. So we may have to ping this again in the new year.

MSNev avatar Dec 22 '23 23:12 MSNev

Hi @MSNev - lmk if you've gotten a response on this. I'm happy to report the feature request elsewhere if there's a better place for it.

johncrim avatar Mar 13 '24 05:03 johncrim

I have not 😞 , let me go and try to revive the thread

MSNev avatar Mar 13 '24 17:03 MSNev

I don't know if https://github.com/microsoft/ApplicationInsights-dotnet/ is any better than this repo for proposing changes to the telemetry model; but in the absence of a better option it might be the most "core" of the SDK libraries.

johncrim avatar Mar 14 '24 05:03 johncrim

Ok, the location to post the request is Azure Monitor - Community

MSNev avatar Mar 14 '24 20:03 MSNev

Thanks @MSNev - I've created that here: https://feedback.azure.com/d365community/idea/9f258d7b-eae2-ee11-a73d-0022484c4e0d

johncrim avatar Mar 15 '24 17:03 johncrim