Azure / Azure/azure-sdk-for-cpp
Connection to Azure Application Insights with OpenTelemetry
- Dominant language
- C++
- Stars
- 205
- Forks
- 172
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 37
Description
**Question**
How must the OpenTelemetry exporter be configured so that the traces will be sent to Azure Monitor?
Is it possible to add an example for the use case or explain how it can be realized with the available functionality.
**Problem**
There is no example in the documention or in the code. Other sdk's for azure provide a method UseAzureMonitor() and they work with the environment variable APPLICATIONINSIGHTS_CONNECTION_STRING.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable?tabs=aspnetcore
**Situation**
Connection string with following structure is known:
"InstrumentationKey=my_key;IngestionEndpoint=my_ingestion_endpoint;LiveEndpoint=my_live_endpoint;ApplicationId=my_app_id"
Following code don't work:
```cpp
opentelemetry::sdk::resource::ResourceAttributes attributes = {
{"service.name", serviceName},
{"service.version", serviceVersion}
};
auto resource = opentelemetry::sdk::resource::Resource::Create(attributes);
opentelemetry::exporter::otlp::OtlpHttpExporterOptions options;
options.url = "my_live_endpoint";
options.http_headers.insert(std::make_pair("InstrumentationKey", "my_key"));
options.http_headers.insert(std::make_pair("ApplicationId", "my_app_id"));
// Create OTLP HTTP exporter
auto exporter = opentelemetry::exporter::otlp::OtlpHttpExporterFactory::Create(options);
// Create test processor
auto processor = opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter));
// Create tracer provider
std::shared_ptr tracerProviderOpenTelemetry = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor), resource);
// Create Azure tracer provider
auto tracerProviderAzure = Azure::Core::Tracing::OpenTelemetry::OpenTelemetryProvider::Create(tracerProviderOpenTelemetry);
// Create Azure Tracer
auto tracerAzure = Azure::Core::Tracing::_internal::TracerProviderImplGetter::TracerImplFromTracer(tracerProviderAzure)->CreateTracer(serviceName, serviceVersion);
auto span = tracerAzure->CreateSpan("AZURE_SPAN", {});
span->AddAttribute("test.suite", "Hello World!");
span->End({});
```
Contributor guide
Assessment
This issue has not been assessed yet.