azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[AzureMonitorOpenTelemetryDistro] AddAzureMonitorOpenTelemetry extension methods and AzureMonitorOpenTelemetryOptions

Open rajkumar-rangaraj opened this issue 2 years ago • 7 comments

Related to #33865

  • Added 4 different public API in this PR. We need to select one or two from the list and discard remaining APIs.
    1. builder.Services.AddAzureMonitorOpenTelemetry()
    2. builder.Services.AddAzureMonitorOpenTelemetry(AzureMonitorOpenTelemetryOptions? options)
    3. builder.Services.AddAzureMonitorOpenTelemetry(builder.Configuration.GetSection("AzureMonitorOpenTelemetry"))
    4. See below,
builder.Services.AddAzureMonitorOpenTelemetry(o =>
{
    o.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
    o.EnableTraces = true;
});
  • Second API does not have capability to read from Configuration, a rebuild is needed if any changes are needed.
  • Third API has ability to read from configuration, but a bind is needed and customer need to pass the specific section of configuration.
  • Fourth API has the ability to read the configuration from DI. Thanks to @CodeBlanch for helping me out on this one.
  • First API could be substituted for any of the above three APIs

Changes

  • Added AzureMonitorOpenTelemetryOptions with nested Traces and Metrics classes.
  • Added template Asp.Net Core example project to show the integration and telemetry collection with Azure Monitor Exporter. Integration parts are in Program.cs and appSettings.json.
  • Added OpenTelemetry.Extensions.Hosting and OpenTelemetry.Instrumentation.AspNetCore package.
{"name":"Request","time":"2023-02-16T00:23:19.9168503Z","iKey":"00000000-0000-0000-0000-000000000000","tags":{"ai.operation.id":"c4328d0fa3de84b218dc2be782601625","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36","ai.operation.name":"GET /","ai.location.ip":null,"ai.cloud.role":"unknown_service:Examples.AspNetCore","ai.cloud.roleInstance":"rajrang-ai","ai.internal.sdkVersion":"dotnet7.0.3:otel1.4.0-rc.4:ext1.0.0-alpha.20230215.1"},"data":{"baseType":"RequestData","baseData":{"id":"9b7836a40b2c590b","name":"GET /","duration":"00:00:00.8437928","success":true,"responseCode":"200","url":"http://localhost:5286/","properties":{"http.flavor":"1.1","_MS.ProcessedByMetricExtractors":"(Name: X,Ver:\u00271.1\u0027)"},"ver":2}}}
{"name":"Metric","time":"2023-02-16T00:24:17.4226322Z","iKey":"00000000-0000-0000-0000-000000000000","tags":{"ai.cloud.role":"unknown_service:Examples.AspNetCore","ai.cloud.roleInstance":"rajrang-ai","ai.internal.sdkVersion":"dotnet7.0.3:otel1.4.0-rc.4:ext1.0.0-alpha.20230215.1"},"data":{"baseType":"MetricData","baseData":{"metrics":[{"ns":"OpenTelemetry.Instrumentation.AspNetCore","name":"http.server.duration","value":843.7928,"count":1,"min":843.7928,"max":843.7928}],"properties":{"http.flavor":"1.1","http.method":"GET","http.route":"/","http.scheme":"http","http.status_code":"200","net.host.name":"localhost","net.host.port":"5286"},"ver":2}}}
{"name":"Metric","time":"2023-02-16T00:24:17.4226641Z","iKey":"00000000-0000-0000-0000-000000000000","tags":{"ai.cloud.role":"unknown_service:Examples.AspNetCore","ai.cloud.roleInstance":"rajrang-ai","ai.internal.sdkVersion":"dotnet7.0.3:otel1.4.0-rc.4:ext1.0.0-alpha.20230215.1"},"data":{"baseType":"MetricData","baseData":{"metrics":[{"name":"requests/duration","value":843.7928,"count":1,"min":843.7928,"max":843.7928}],"properties":{"_MS.IsAutocollected":"True","_MS.MetricId":"requests/duration","cloud/roleInstance":"rajrang-ai","cloud/roleName":"unknown_service:Examples.AspNetCore","Request.Success":"True","request/resultCode":"200"},"ver":2}}}

Enriched with AspNetCoreInstrumentationOptions

{"name":"Request","time":"2023-02-16T01:15:59.0599609Z","iKey":"00000000-0000-0000-0000-000000000000","tags":{"ai.operation.id":"bcd6411f5a25189558b8ec43f849c617","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36","ai.operation.name":"GET /","ai.location.ip":null,"ai.cloud.role":"unknown_service:Examples.AspNetCore","ai.cloud.roleInstance":"rajrang-ai","ai.internal.sdkVersion":"dotnet7.0.3:otel1.4.0-rc.4:ext1.0.0-alpha.20230215.1"},"data":{"baseType":"RequestData","baseData":{"id":"229bc348928ff667","name":"GET /","duration":"00:00:00.3128591","success":true,"responseCode":"200","url":"http://localhost:5286/","properties":{"http.flavor":"1.1","requestProtocol":"HTTP/1.1","_MS.ProcessedByMetricExtractors":"(Name: X,Ver:\u00271.1\u0027)"},"ver":2}}}

rajkumar-rangaraj avatar Feb 15 '23 23:02 rajkumar-rangaraj

In my opinion, you should remove everything from the example project that isn't relevant to the OTel. I would remove the wwwroot, Privacy, and Error pages.

TimothyMothra avatar Feb 15 '23 23:02 TimothyMothra

Services.AddAzureMonitorOpenTelemetry() Services.AddAzureMonitorOpenTelemetry(IConfiguration config) => usage Services.AddAzureMonitorOpenTelemetry(builder.Configuration.GetSection("AzureMonitorOpenTelemetry")) Services.AddAzureMonitorOpenTelemetry(AzureMonitorOpenTelemetryOptions options)

Could we remove the ones taking IConfiguration? Why are they needed....

cijothomas avatar Feb 15 '23 23:02 cijothomas

Could we remove the ones taking IConfiguration? Why are they needed....

If someone wants to use read the value from appSettings.json or environment variable this should help. Technically, they could bind outside and pass it as a options too. I don't have a strong preference, waiting to hear more feedback on it.

rajkumar-rangaraj avatar Feb 16 '23 00:02 rajkumar-rangaraj

In my opinion, you should remove everything from the example project that isn't relevant to the OTel. I would remove the wwwroot, Privacy, and Error pages.

https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/trace/getting-started-aspnetcore use this approach to get a leaner example.

cijothomas avatar Feb 16 '23 00:02 cijothomas

API change check

APIView has identified API level changes in this PR and created following API reviews.

Azure.Monitor.OpenTelemetry

azure-sdk avatar Feb 16 '23 00:02 azure-sdk

Could we remove the ones taking IConfiguration? Why are they needed....

If someone wants to use read the value from appSettings.json or environment variable this should help. Technically, they could bind outside and pass it as a options too. I don't have a strong preference, waiting to hear more feedback on it.

I think we could retrieve it ourselves from DI...

cijothomas avatar Feb 16 '23 00:02 cijothomas

Updated PR description.

rajkumar-rangaraj avatar Feb 16 '23 07:02 rajkumar-rangaraj

Suggestions for options:

  • Have a method to add identifiers for custom metrics
  • Have a method to add identifiers for custom ActivitySources
    • Should both of these be available through configuration? Is this something an SRE would want to change at runtime without having to go back to the developer to change?
  • Have an option for dumping traces to the console, defaults to off, but samples should set this based on Environment.IsDevelopment,. This would map to the .AddConsoleExporter() for tracing.

Edit: This PR can go in without, and add later.

samsp-msft avatar Feb 17 '23 20:02 samsp-msft

Added 4 different public API in this PR. We need to select one or two from the list and discard remaining APIs

If all four were useful I'd suggest keeping all 4, I don't know why we'd limited to only having a certain number. That said I think the 2nd and 3rd have limited utility and might cause people to shoot themselves in the foot with non-standard or non-reloadable configurations. I'd suggest starting with 1+4 and then listen to user feedback to see if that is sufficient.

noahfalk avatar Feb 23 '23 00:02 noahfalk

In the first beta version, we plan to include all 4 public APIs that have been proposed. However, we may choose to remove some of them after considering customer feedback and any potential supportability issues that arise.

rajkumar-rangaraj avatar Feb 23 '23 05:02 rajkumar-rangaraj

Opinion: AddAzureMonitorOpenTelemetry should have the same overloads and functionality as AddApplicationInsightsTelemetry, including the ability to use the APPLICATIONINSIGHTS_CONNECTION_STRING env var. See the docs.

image

Personally, I'm looking to use option #3 in the PR description here, or an env var (again, preferably APPLICATIONINSIGHTS_CONNECTION_STRING because I'm already passing that env var to my application).

alexdresko avatar Feb 23 '23 13:02 alexdresko

Opinion: AddAzureMonitorOpenTelemetry should have the same overloads and functionality as AddApplicationInsightsTelemetry, including the ability to use the APPLICATIONINSIGHTS_CONNECTION_STRING env var. See the docs.

image

Personally, I'm looking to use option #3 in the PR description here, or an env var (again, preferably APPLICATIONINSIGHTS_CONNECTION_STRING because I'm already passing that env var to my application).

APPLICATIONINSIGHTS_CONNECTION_STRING would definitely be supported.

cijothomas avatar Feb 23 '23 15:02 cijothomas

Opinion: AddAzureMonitorOpenTelemetry should have the same overloads and functionality as AddApplicationInsightsTelemetry, including the ability to use the APPLICATIONINSIGHTS_CONNECTION_STRING env var. See the docs.

image

Personally, I'm looking to use option #3 in the PR description here, or an env var (again, preferably APPLICATIONINSIGHTS_CONNECTION_STRING because I'm already passing that env var to my application).

Alternatively, you could use

builder.Services.Configure<AzureMonitorOpenTelemetryOptions>(builder.Configuration.GetSection("AzureMonitorOpenTelemetry"));

beta-1 version of this distribution will have support for APPLICATIONINSIGHTS_CONNECTION_STRING .

rajkumar-rangaraj avatar Feb 23 '23 21:02 rajkumar-rangaraj

The pull request and its description have been updated following the feedback. Now, we have implementation of these three public APIs

1. builder.Services.AddAzureMonitorOpenTelemetry() 2. builder.Services.AddAzureMonitorOpenTelemetry(AzureMonitorOpenTelemetryOptions options) 3. builder.Services.AddAzureMonitorOpenTelemetry(Action<AzureMonitorOpenTelemetryOptions> configureAzureMonitorOpenTelemetry);

rajkumar-rangaraj avatar Feb 23 '23 21:02 rajkumar-rangaraj

Since this is merged, does the nuget package get updated automatically? If not, when will this be in the nuget package?

alexdresko avatar Feb 24 '23 18:02 alexdresko