Skip to content
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

Bring CustomPropertiesImpl back in v3 so that correlationContext's customProperities can be used again #1379

Open
zhiyuanliang-ms opened this issue Sep 5, 2024 · 2 comments

Comments

@zhiyuanliang-ms
Copy link
Contributor

zhiyuanliang-ms commented Sep 5, 2024

In v2, the below pattern works well for me:

appInsights.setup(connectionString)
    .setAutoCollectRequests(true)
    .setSendLiveMetrics(true)
    .start();

const attachMyTag = (envelope) => {
  const context = appInsights.getCorrelationContext();
  if (context) {
    envelope.data.baseData.properties["MyTag"] = context.customProperties.getProperty("MyTag");
  }
}

appInsights.defaultClient.addTelemetryProcessor(attachTargetingId);

const express = require('express');
const app = express();
const port = 5000;

app.get('/', (req, res) => {
  const context = appInsights.getCorrelationContext();
  context.customProperties.setProperty("MyTag", "123")

  appInsights.defaultClient.trackEvent({name: "TestEvent"})
  res.send(`hello`);
});

The correlation context is per-request-scoped, I used correlationContext.customProperties to store some information which I want to be tagged to all telemetry emitted during the request. This is very helpful if I want to tag something into the request telemetry automatically emitted by app insights.

But in v3, CorrelationContext's custom properties are stubbed out source code
It is impossible for me to achieve the same thing. Or should I use span.attribute instead?

@hectorhdzg
Copy link
Member

@zhiyuanliang-ms you should be able to achieve the same thing using Span attributes like you mentioned, Application Insights v3 was created for easy migration to OpenTelemetry for simple scenarios, in this case I recommend to take OpenTelemetry approach, logs will not include the attributes and you will need to add them using the LogRecord attributes as well.

@ricardasjak
Copy link

@zhiyuanliang-ms you should be able to achieve the same thing using Span attributes like you mentioned, Application Insights v3 was created for easy migration to OpenTelemetry for simple scenarios, in this case I recommend to take OpenTelemetry approach, logs will not include the attributes and you will need to add them using the LogRecord attributes as well.

I have same problem as reporter. Could you, please, elaborate more how to use OpenTelemetry approach? Do I have to entirely ditch out AI v3 and replace it with Azure Monitor OT library(-ies)?

Hence, I find it difficult to master AI v3, when quite a few methods are still callable, but they are actually doing nothing, and no single error or warning thrown. ;-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants