Skip to content

Commit

Permalink
Merge branch 'main' into vibankwa/fix-httpclient-metric-network-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
vishweshbankwar authored Feb 24, 2023
2 parents 62ea151 + 0971088 commit 63cd608
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 325 deletions.
5 changes: 0 additions & 5 deletions examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ internal static object Run(MetricsOptions options)
*
*/

// Adding the OtlpExporter creates a GrpcChannel.
// This switch must be set before creating a GrpcChannel when calling an insecure gRPC service.
// See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

providerBuilder
.AddOtlpExporter((exporterOptions, metricReaderOptions) =>
{
Expand Down
5 changes: 0 additions & 5 deletions examples/Console/TestOtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ internal static object Run(string endpoint, string protocol)

private static object RunWithActivitySource(string endpoint, string protocol)
{
// Adding the OtlpExporter creates a GrpcChannel.
// This switch must be set before creating a GrpcChannel when calling an insecure gRPC service.
// See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

var otlpExportProtocol = ToOtlpExportProtocol(protocol);
if (!otlpExportProtocol.HasValue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api.ProviderBuilderExtensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Installation

```shell
dotnet add package --prerelease OpenTelemetry.Api.ProviderBuilderExtensions
dotnet add package OpenTelemetry.Api.ProviderBuilderExtensions
```

## Overview
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* `AddOtlpExporter` extension methods will now always create a new options
instance when named options are NOT used.
([#4200](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4200))

## 1.4.0-rc.4

Released 2023-Feb-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,25 @@ public static MeterProviderBuilder AddOtlpExporter(

return builder.AddReader(sp =>
{
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<OtlpExporterOptions>>().Get(finalOptionsName);
OtlpExporterOptions exporterOptions;

if (name == null && configureExporter != null)
if (name == null)
{
// If we are NOT using named options, we execute the
// configuration delegate inline. The reason for this is
// If we are NOT using named options we create a new
// instance always. The reason for this is
// OtlpExporterOptions is shared by all signals. Without a
// name, delegates for all signals will mix together. See:
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043
configureExporter(exporterOptions);
exporterOptions = sp.GetRequiredService<IOptionsFactory<OtlpExporterOptions>>().Create(finalOptionsName);

// Configuration delegate is executed inline on the fresh instance.
configureExporter?.Invoke(exporterOptions);
}
else
{
// When using named options we can properly utilize Options
// API to create or reuse an instance.
exporterOptions = sp.GetRequiredService<IOptionsMonitor<OtlpExporterOptions>>().Get(finalOptionsName);
}

return BuildOtlpExporterMetricReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ public static TracerProviderBuilder AddOtlpExporter(

return builder.AddProcessor(sp =>
{
var exporterOptions = sp.GetRequiredService<IOptionsMonitor<OtlpExporterOptions>>().Get(finalOptionsName);
OtlpExporterOptions exporterOptions;

if (name == null && configure != null)
if (name == null)
{
// If we are NOT using named options, we execute the
// configuration delegate inline. The reason for this is
// If we are NOT using named options we create a new
// instance always. The reason for this is
// OtlpExporterOptions is shared by all signals. Without a
// name, delegates for all signals will mix together. See:
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/4043
configure(exporterOptions);
exporterOptions = sp.GetRequiredService<IOptionsFactory<OtlpExporterOptions>>().Create(finalOptionsName);

// Configuration delegate is executed inline on the fresh instance.
configure?.Invoke(exporterOptions);
}
else
{
// When using named options we can properly utilize Options
// API to create or reuse an instance.
exporterOptions = sp.GetRequiredService<IOptionsMonitor<OtlpExporterOptions>>().Get(finalOptionsName);
}

// Note: Not using finalOptionsName here for SdkLimitOptions.
Expand Down
102 changes: 65 additions & 37 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,88 @@ implementation.

## Prerequisite

* [Get OpenTelemetry Collector](https://opentelemetry.io/docs/collector/)
* An endpoint capable of accepting OTLP, like [OpenTelemetry
Collector](https://opentelemetry.io/docs/collector/) or similar.

## Installation

```shell
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
```

## Enable Trace Exporter

This exporter provides `AddOtlpExporter()` extension method on `TracerProviderBuilder`
to enable exporting of traces. The following snippet adds the Exporter with default
[configuration](#configuration).

```csharp
var tracerProvider = Sdk.CreateTracerProviderBuilder()
// rest of config not shown here.
.AddOtlpExporter()
.Build();
```

See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for
runnable example.

## Enable Metric Exporter

This exporter provides `AddOtlpExporter()` extension method on `MeterProviderBuilder`
to enable exporting of metrics. The following snippet adds the Exporter with default
[configuration](#configuration).

```csharp
var meterProvider = Sdk.CreateMeterProviderBuilder()
// rest of config not shown here.
.AddOtlpExporter()
.Build();
```

See the [`TestMetrics.cs`](../../examples/Console/TestMetrics.cs) for
runnable example.

## Enable Log Exporter

This package currently only supports exporting traces and metrics. Support for
exporting logs is provided by installing the
[`OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs`](../OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/README.md)
package.

Once the OTLP log exporter is stable, it'll be folded into this package. Check
[this](https://github.com/open-telemetry/opentelemetry-dotnet/milestone/35)
milestone for tracking.

## Configuration

You can configure the `OtlpExporter` through `Options` types properties
You can configure the `OtlpExporter` through `OtlpExporterOptions`
and environment variables.
The `Options` type setters take precedence over the environment variables.
The `OtlpExporterOptions` type setters take precedence over the environment variables.

## Options Properties
This can be achieved by providing an `Action<OtlpExporterOptions>` delegate to the
`AddOtlpExporter()` method.

* `BatchExportProcessorOptions`: Configuration options for the batch exporter.
Only used if ExportProcessorType is set to Batch.
TODO: Show metrics specific configuration (i.e MetricReaderOptions).

* `Endpoint`: Target to which the exporter is going to send traces or metrics.
The endpoint must be a valid Uri with scheme (http or https) and host, and MAY
contain a port and path.
## OtlpExporterOptions

* `ExportProcessorType`: Whether the exporter should use [Batch or Simple
exporting
processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#built-in-span-processors).
The default is Batch.

* `BatchExportProcessorOptions`: Configuration options for the batch exporter.
Only used if ExportProcessorType is set to Batch.

* `Protocol`: OTLP transport protocol. Supported values:
`OtlpExportProtocol.Grpc` and `OtlpExportProtocol.HttpProtobuf`.
The default is `OtlpExportProtocol.Grpc`.

* `Endpoint`: Target to which the exporter is going to send traces or metrics.
The endpoint must be a valid Uri with scheme (http or https) and host, and MAY
contain a port and path. The default is "localhost:4317" for
`OtlpExportProtocol.Grpc` and "localhost:4318" for
`OtlpExportProtocol.HttpProtobuf`.

* `Headers`: Optional headers for the connection.

Expand All @@ -44,9 +100,6 @@ The `Options` type setters take precedence over the environment variables.

* `TimeoutMilliseconds` : Max waiting time for the backend to process a batch.

* `Protocol`: OTLP transport protocol. Supported values:
`OtlpExportProtocol.Grpc` and `OtlpExportProtocol.HttpProtobuf`.

See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for
an example of how to use the exporter.

Expand Down Expand Up @@ -90,31 +143,6 @@ values of the span limits
* `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT`
* `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT`

## OTLP Logs

This package currently only supports exporting traces and metrics. Support for
exporting logs is provided by installing the
[`OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs`](../OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs/README.md)
package.

Once the OTLP log exporter is stable, it'll be folded into this package. Check
[this](https://github.com/open-telemetry/opentelemetry-dotnet/milestone/35)
milestone for tracking.

## Special case when using insecure channel

If your application is targeting .NET Core 3.1, and you are using an insecure
(HTTP) endpoint, the following switch must be set before adding `OtlpExporter`.

```csharp
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
true);
```

See
[this](https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client)
for more information.

## Configure HttpClient

The `HttpClientFactory` option is provided on `OtlpExporterOptions` for users
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions
OpenTelemetry.Metrics.MeterProviderBuilderExtensions
OpenTelemetry.OpenTelemetryBuilder
OpenTelemetry.OpenTelemetryBuilder.ConfigureResource(System.Action<OpenTelemetry.Resources.ResourceBuilder!>! configure) -> OpenTelemetry.OpenTelemetryBuilder!
OpenTelemetry.OpenTelemetryBuilder.Services.get -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
OpenTelemetry.OpenTelemetryBuilder.WithMetrics() -> OpenTelemetry.OpenTelemetryBuilder!
OpenTelemetry.OpenTelemetryBuilder.WithMetrics(System.Action<OpenTelemetry.Metrics.MeterProviderBuilder!>! configure) -> OpenTelemetry.OpenTelemetryBuilder!
OpenTelemetry.OpenTelemetryBuilder.WithTracing() -> OpenTelemetry.OpenTelemetryBuilder!
OpenTelemetry.OpenTelemetryBuilder.WithTracing(System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> OpenTelemetry.OpenTelemetryBuilder!
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetry(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> OpenTelemetry.OpenTelemetryBuilder!
static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Metrics.MeterProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.OpenTelemetryServicesExtensions.AddOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.Configure(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, System.Action<System.IServiceProvider!, OpenTelemetry.Metrics.MeterProviderBuilder!>! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.GetServices(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.Configure(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action<System.IServiceProvider!, OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.GetServices(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!

4 changes: 4 additions & 0 deletions src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Removed deprecated extensions: `AddOpenTelemetryTracing`,
`AddOpenTelemetryMetrics`, `Configure`, & `GetServices`.
([#4071](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4071))

## 1.4.0-rc.4

Released 2023-Feb-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ internal static void Initialize(IServiceProvider serviceProvider)
{
Debug.Assert(serviceProvider != null, "serviceProvider was null");

var meterProvider = serviceProvider.GetService<MeterProvider>();
var meterProvider = serviceProvider!.GetService<MeterProvider>();
if (meterProvider == null)
{
HostingExtensionsEventSource.Log.MeterProviderNotRegistered();
}

var tracerProvider = serviceProvider.GetService<TracerProvider>();
var tracerProvider = serviceProvider!.GetService<TracerProvider>();
if (tracerProvider == null)
{
HostingExtensionsEventSource.Log.TracerProviderNotRegistered();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Description>Contains extensions to start OpenTelemetry in applications using Microsoft.Extensions.Hosting</Description>
<RootNamespace>OpenTelemetry</RootNamespace>
<MinVerTagPrefix>core-</MinVerTagPrefix>
<Nullable>enable</Nullable>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>

<!--Do not run ApiCompat for netstandard2.0 as this is newly added. Remove this property once we have released a stable version.-->
Expand All @@ -15,8 +16,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsHostingAbstractionsPkgVer)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 63cd608

Please sign in to comment.