Skip to content

Commit 1a2f548

Browse files
Merge branch 'main' into 5430_syncShared
2 parents 928c039 + dd4e212 commit 1a2f548

File tree

72 files changed

+2771
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2771
-457
lines changed

Diff for: src/OpenTelemetry.Api.ProviderBuilderExtensions/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 1.8.0-beta.1
6+
7+
Released 2024-Mar-14
8+
59
* Added `IOpenTelemetryBuilder` interface to support authoring extensions which
610
can configure multiple OpenTelemetry signals (tracing, metrics, and/or logs).
711
([#5265](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5265))

Diff for: src/OpenTelemetry.Api/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 1.8.0-beta.1
6+
7+
Released 2024-Mar-14
8+
59
## 1.7.0
610

711
Released 2023-Dec-08

Diff for: src/OpenTelemetry.Exporter.Console/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 1.8.0-beta.1
6+
7+
Released 2024-Mar-14
8+
59
## 1.7.0
610

711
Released 2023-Dec-08

Diff for: src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 1.8.0-beta.1
6+
7+
Released 2024-Mar-14
8+
59
## 1.7.0
610

711
Released 2023-Dec-08

Diff for: src/OpenTelemetry.Exporter.OpenTelemetryProtocol/.publicApi/Stable/PublicAPI.Shipped.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#nullable enable
2-
~OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity>
3-
~OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
4-
~OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri
5-
~OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
6-
~OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string
7-
~OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
8-
~OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.get -> System.Func<System.Net.Http.HttpClient>
9-
~OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void
2+
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity!>!
3+
OpenTelemetry.Exporter.OtlpExporterOptions.BatchExportProcessorOptions.set -> void
4+
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.get -> System.Uri!
5+
OpenTelemetry.Exporter.OtlpExporterOptions.Endpoint.set -> void
6+
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.get -> string?
7+
OpenTelemetry.Exporter.OtlpExporterOptions.Headers.set -> void
8+
OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.get -> System.Func<System.Net.Http.HttpClient!>!
9+
OpenTelemetry.Exporter.OtlpExporterOptions.HttpClientFactory.set -> void
1010
~OpenTelemetry.Exporter.OtlpMetricExporter.OtlpMetricExporter(OpenTelemetry.Exporter.OtlpExporterOptions options) -> void
1111
~OpenTelemetry.Exporter.OtlpTraceExporter.OtlpTraceExporter(OpenTelemetry.Exporter.OtlpExporterOptions options) -> void
1212
~override OpenTelemetry.Exporter.OtlpMetricExporter.Export(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics) -> OpenTelemetry.ExportResult
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OpenTelemetry.OpenTelemetryBuilderOtlpExporterExtensions
2+
static OpenTelemetry.OpenTelemetryBuilderOtlpExporterExtensions.UseOtlpExporter(this OpenTelemetry.IOpenTelemetryBuilder! builder) -> OpenTelemetry.IOpenTelemetryBuilder!
3+
static OpenTelemetry.OpenTelemetryBuilderOtlpExporterExtensions.UseOtlpExporter(this OpenTelemetry.IOpenTelemetryBuilder! builder, OpenTelemetry.Exporter.OtlpExportProtocol protocol, System.Uri! baseEndpoint) -> OpenTelemetry.IOpenTelemetryBuilder!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#nullable enable
5+
6+
using Microsoft.Extensions.Configuration;
7+
using OpenTelemetry.Exporter;
8+
using OpenTelemetry.Internal;
9+
10+
namespace OpenTelemetry;
11+
12+
/// <summary>
13+
/// Contains extension methods to facilitate registration of the OpenTelemetry
14+
/// Protocol (OTLP) exporter into an <see cref="IOpenTelemetryBuilder"/>
15+
/// instance.
16+
/// </summary>
17+
public static class OpenTelemetryBuilderOtlpExporterExtensions
18+
{
19+
/// <summary>
20+
/// Uses OpenTelemetry Protocol (OTLP) exporter for all signals.
21+
/// </summary>
22+
/// <remarks>
23+
/// Notes:
24+
/// <list type="bullet">
25+
/// <item>Calling this method automatically enables logging, metrics, and
26+
/// tracing.</item>
27+
/// <item>The exporter registered by this method will be added as the last
28+
/// processor in the pipeline established for logging and tracing.</item>
29+
/// <item>This method can only be called once. Subsequent calls will results
30+
/// in a <see cref="NotSupportedException"/> being thrown.</item>
31+
/// <item>This method cannot be called in addition to signal-specific
32+
/// <c>AddOtlpExporter</c> methods. If this method is called signal-specific
33+
/// <c>AddOtlpExporter</c> calls will result in a <see
34+
/// cref="NotSupportedException"/> being thrown.</item>
35+
/// </list>
36+
/// </remarks>
37+
/// <param name="builder"><see cref="IOpenTelemetryBuilder"/>.</param>
38+
/// <returns>Supplied <see cref="IOpenTelemetryBuilder"/> for chaining calls.</returns>
39+
public static IOpenTelemetryBuilder UseOtlpExporter(
40+
this IOpenTelemetryBuilder builder)
41+
=> UseOtlpExporter(builder, name: null, configuration: null, configure: null);
42+
43+
/// <summary><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)"/></summary>
44+
/// <remarks><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/remarks"/></remarks>
45+
/// <returns><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/returns"/></returns>
46+
/// <param name="builder"><see cref="IOpenTelemetryBuilder"/>.</param>
47+
/// <param name="protocol"><see cref="OtlpExportProtocol"/>.</param>
48+
/// <param name="baseEndpoint">
49+
/// <para>Base endpoint to use.</para>
50+
/// Note: A signal-specific path will be appended to the base endpoint for
51+
/// each signal automatically if the protocol is set to <see
52+
/// cref="OtlpExportProtocol.HttpProtobuf"/>.
53+
/// </param>
54+
public static IOpenTelemetryBuilder UseOtlpExporter(
55+
this IOpenTelemetryBuilder builder,
56+
OtlpExportProtocol protocol,
57+
Uri baseEndpoint)
58+
{
59+
Guard.ThrowIfNull(baseEndpoint);
60+
61+
return UseOtlpExporter(builder, name: null, configuration: null, configure: otlpBuilder =>
62+
{
63+
otlpBuilder.ConfigureDefaultExporterOptions(o =>
64+
{
65+
o.Protocol = protocol;
66+
o.Endpoint = baseEndpoint;
67+
});
68+
});
69+
}
70+
71+
/// <summary><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)"/></summary>
72+
/// <remarks><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/remarks"/></remarks>
73+
/// <returns><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/returns"/></returns>
74+
/// <param name="builder"><see cref="IOpenTelemetryBuilder"/>.</param>
75+
/// <param name="configure">Callback action for configuring <see cref="OtlpExporterBuilder"/>.</param>
76+
internal static IOpenTelemetryBuilder UseOtlpExporter(
77+
this IOpenTelemetryBuilder builder,
78+
Action<OtlpExporterBuilder> configure)
79+
{
80+
Guard.ThrowIfNull(configure);
81+
82+
return UseOtlpExporter(builder, name: null, configuration: null, configure);
83+
}
84+
85+
/// <summary><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)"/></summary>
86+
/// <remarks><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/remarks"/></remarks>
87+
/// <returns><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/returns"/></returns>
88+
/// <param name="builder"><see cref="IOpenTelemetryBuilder"/>.</param>
89+
/// <param name="configuration">
90+
/// <para><see cref="IConfiguration"/> to bind onto <see cref="OtlpExporterBuilderOptions"/>.</para>
91+
/// <para>Notes:
92+
/// <list type="bullet">
93+
/// <item docLink="true">See [TODO:Add doc link] for details on the configuration
94+
/// schema.</item>
95+
/// <item>The <see cref="OtlpExporterBuilderOptions"/> instance will be
96+
/// named "otlp" by default when calling this method.</item>
97+
/// </list>
98+
/// </para>
99+
/// </param>
100+
internal static IOpenTelemetryBuilder UseOtlpExporter(
101+
this IOpenTelemetryBuilder builder,
102+
IConfiguration configuration)
103+
{
104+
Guard.ThrowIfNull(configuration);
105+
106+
return UseOtlpExporter(builder, name: null, configuration, configure: null);
107+
}
108+
109+
/// <summary><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)"/></summary>
110+
/// <remarks><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/remarks"/></remarks>
111+
/// <returns><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder)" path="/returns"/></returns>
112+
/// <param name="builder"><see cref="IOpenTelemetryBuilder"/>.</param>
113+
/// <param name="name">Optional name which is used when retrieving options.</param>
114+
/// <param name="configuration">
115+
/// <para>Optional <see cref="IConfiguration"/> to bind onto <see
116+
/// cref="OtlpExporterBuilderOptions"/>.</para>
117+
/// <para>Notes:
118+
/// <list type="bullet">
119+
/// <item><inheritdoc cref="UseOtlpExporter(IOpenTelemetryBuilder,
120+
/// IConfiguration)"
121+
/// path="/param[@name='configuration']/para/list/item[@docLink='true']"/></item>
122+
/// <item>If <paramref name="name"/> is not set the <see
123+
/// cref="OtlpExporterBuilderOptions"/> instance will be named "otlp" by
124+
/// default when <paramref name="configuration"/> is used.</item>
125+
/// </list>
126+
/// </para>
127+
/// </param>
128+
/// <param name="configure">Optional callback action for configuring <see cref="OtlpExporterBuilder"/>.</param>
129+
internal static IOpenTelemetryBuilder UseOtlpExporter(
130+
this IOpenTelemetryBuilder builder,
131+
string? name,
132+
IConfiguration? configuration,
133+
Action<OtlpExporterBuilder>? configure)
134+
{
135+
Guard.ThrowIfNull(builder);
136+
137+
// Note: We automatically turn on signals for "UseOtlpExporter"
138+
builder
139+
.WithLogging()
140+
.WithMetrics()
141+
.WithTracing();
142+
143+
var otlpBuilder = new OtlpExporterBuilder(builder.Services, name, configuration);
144+
145+
configure?.Invoke(otlpBuilder);
146+
147+
return builder;
148+
}
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace OpenTelemetry.Exporter;
7+
8+
internal static class OpenTelemetryBuilderServiceProviderExtensions
9+
{
10+
public static void EnsureSingleUseOtlpExporterRegistration(this IServiceProvider serviceProvider)
11+
{
12+
var registrations = serviceProvider.GetServices<UseOtlpExporterRegistration>();
13+
if (registrations.Count() > 1)
14+
{
15+
throw new NotSupportedException("Multiple calls to UseOtlpExporter on the same IServiceCollection are not supported.");
16+
}
17+
}
18+
19+
public static void EnsureNoUseOtlpExporterRegistrations(this IServiceProvider serviceProvider)
20+
{
21+
var registrations = serviceProvider.GetServices<UseOtlpExporterRegistration>();
22+
if (registrations.Any())
23+
{
24+
throw new NotSupportedException("Signal-specific AddOtlpExporter methods and the cross-cutting UseOtlpExporter method being invoked on the same IServiceCollection is not supported.");
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)