Closed eric-gonzalez-tfs closed 1 month ago
Hi Team, any insight here would be much appreciated.
Hi @hectorhdzg, any advice here?
@eric-gonzalez-tfs sorry for the delay, yes this a topic we had been discussing last few weeks, because of OpenTelemetry architecture having multiple clients independent on each other is not achievable anymore, this can be done in a different way depending on your scenario, you basically call useAzureMonitor method to initialize all OpenTelemetry components, then you can create a custom Span Processor sending to Azure Monitor as well using different sampling ratio, I can provide some code sample if it works.
@eric-gonzalez-tfs sorry for the delay, yes this a topic we had been discussing last few weeks, because of OpenTelemetry architecture having multiple clients independent on each other is not achievable anymore, this can be done in a different way depending on your scenario, you basically call useAzureMonitor method to initialize all OpenTelemetry components, then you can create a custom Span Processor sending to Azure Monitor as well using different sampling ratio, I can provide some code sample if it works.
@hectorhdzg Thank you for the response - that would be great.
You can do something like this
import { useAzureMonitor, AzureMonitorOpenTelemetryOptions } from "applicationinsights";
import { AzureMonitorTraceExporter, ApplicationInsightsSampler } from "@azure/monitor-opentelemetry-exporter";
import { BatchSpanProcessor} from "@opentelemetry/sdk-trace-base";
import { NodeTracerProvider, NodeTracerConfig } from "@opentelemetry/sdk-trace-node";
// Initialize OpenTelemetry, all data will be sampled in
useAzureMonitor({
samplingRatio: 1
});
// Create another Tracer Provider using different sampling mechanism
const aiSampler = new ApplicationInsightsSampler(0.5);
const tracerConfig: NodeTracerConfig = {
sampler: aiSampler,
};
const tracerProvider = new NodeTracerProvider(tracerConfig);
// Add SpanProcessor sending with different sampling ratio
let azureMonitorExporter = new AzureMonitorTraceExporter({
connectionString: "your_connectionString",
})
tracerProvider.addSpanProcessor(new BatchSpanProcessor(azureMonitorExporter));
const span= tracerProvider.getTracer("tesTracer").startSpan("testSpan");
span.end();
@eric-gonzalez-tfs Do you have any further questions on this issue? Or did the above answer your question?
Haven't had a chance to test this myself, but the code snipped should suffice. Thanks!
I am using
applicationinsights@3.0.0-beta.6
.The project I'm working on requires certain data to ALWAYS be sent, and others to be sent on a sampling ratio.
When I try to initialize a second client with a 100% sampling ratio and most autocollection config off, I get a duplicate registration error.![Screenshot 2023-06-27 at 1 28 02 PM](https://github.com/microsoft/ApplicationInsights-node.js/assets/82120345/274bb493-5f95-449e-bfa2-a9810cca68bc)
What is the best way to create a second client that sends 100% of the data without initializing anything else under the hood?