Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.07k stars 1.2k forks source link

[@azure/monitor-opentelemetry-exporter] Send Custom Event to AI #29196

Open gunzip opened 6 months ago

gunzip commented 6 months ago

Is your feature request related to a problem? Please describe.

We are interested in utilizing OpenTelemetry with Azure Monitor and also want to send Custom Events to Application Insights.

As per the documentation, currently, this capability is not supported, requiring us to fall back on the classic Application Insights SDK.

At the moment, all types of span events are categorized as "Traces" in Application Insights, which is a significant barrier for us in adopting OpenTelemetry.

Describe the solution you'd like

According to the documentation here, the ability to send Custom Events via OpenTelemetry Azure Monitor is supposed to be "available as a public preview", but I haven't been able to find any further information on this. Could you provide an estimated time of arrival for this feature?

Is there any known workaround? At the very least, we're interested in the possibility of sharing configurations (e.g., sampling rate) between Azure Monitor and the default Application Insights client, just in case.

Thank you for your work!

Describe alternatives you've considered

Reverting to the classic Application Insights SDK.

github-actions[bot] commented 6 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @hectorhdzg @JacksonWeber @ramthi.

gunzip commented 6 months ago

Update. I've found this workaround, but it depends on some internals. Maybe we can automatically route traces to customEvents in case they've got custom properties?

const trackCustomEvent = (
  name: string,
  properties: Record<string, string>,
  loggerName = "default",
) => {
  const data /* TelemetryEventData */ = {
    // event name
    name,
    // required
    version: 2,
  };
  logs.getLogger(loggerName).emit({
    severityNumber: SeverityNumber.INFO,
    severityText: "INFO",
    body: JSON.stringify(data),
    attributes: { ...properties, "_MS.baseType": "EventData" },
  });
};
JacksonWeber commented 6 months ago

Hi @gunzip, it is correct that custom events are in public preview. That's referring to the beta for ApplicationInsights Version 3, which is built on OpenTelemetry, but provides an API that should be familiar to those using the current version of ApplicationInsights.

We're currently tracking custom events to GA in the next six months.

As for the workaround, this appears to be similar to what's achieved by the beta mentioned above, so you may want to simply use that project if it meets your needs with its limitations.

eric-gonzalez-tfs commented 3 weeks ago

Hi @gunzip - thank you for the sample. I too had a requirement to track custom events, but needed to use some of the OTel functionality that the Azure Monitor package provides.

For anyone landing on this and wanting to know how to send custom events using Azure Monitor, you can follow what the Application Insights package does to send Custom Events via OTel here. The data flows from trackEvent to _eventToLogRecord to _telemetryToLogRecord and ultimately gets emitted via OTel logger as your example suggests.

It's pretty easy to follow and I was able to get it working by slightly modifying this helper function to my needs.

BTW - @JacksonWeber - who can we reach out to to get on the Public Preview for custom events?