// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // using Microsoft.Extensions.Hosting; using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; namespace Microsoft.Extensions.DependencyInjection; /// /// Extension methods for setting up OpenTelemetry services in an . /// public static class OpenTelemetryServicesExtensions { /// /// Configure OpenTelemetry and register a /// to automatically start tracing services in the supplied . /// /// /// Notes: /// /// /// This is safe to be called multiple times. Only a single will be created for a given . /// /// /// This method should be called by application host code. Library /// authors should call /// instead. /// /// /// /// . /// Supplied for chaining /// calls. [Obsolete("Use the AddOpenTelemetry().WithTracing(configure).StartWithHost() pattern instead. This method will be removed in a future version.")] public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services) => AddOpenTelemetryTracing(services, b => { }); /// /// Configure OpenTelemetry and register a /// to automatically start tracing services in the supplied . /// /// /// . /// Callback action to configure the . /// Supplied for chaining /// calls. [Obsolete("Use the AddOpenTelemetry().WithTracing(configure).StartWithHost() pattern instead. This method will be removed in a future version.")] public static IServiceCollection AddOpenTelemetryTracing(this IServiceCollection services, Action configure) { services.AddOpenTelemetry().WithTracing(configure).StartWithHost(); return services; } /// /// Configure OpenTelemetry and register a /// to automatically start metric services in the supplied . /// /// /// Notes: /// /// /// This is safe to be called multiple times. Only a single will be created for a given . /// /// /// This method should be called by application host code. Library /// authors should call /// instead. /// /// /// /// . /// Supplied for chaining /// calls. [Obsolete("Use the AddOpenTelemetry().WithMetrics(configure).StartWithHost() pattern instead. This method will be removed in a future version.")] public static IServiceCollection AddOpenTelemetryMetrics(this IServiceCollection services) => AddOpenTelemetryMetrics(services, b => { }); /// /// Configure OpenTelemetry and register a /// to automatically start metric services in the supplied . /// /// /// . /// Callback action to configure the . /// Supplied for chaining /// calls. [Obsolete("Use the AddOpenTelemetry().WithMetrics(configure).StartWithHost() pattern instead. This method will be removed in a future version.")] public static IServiceCollection AddOpenTelemetryMetrics(this IServiceCollection services, Action configure) { services.AddOpenTelemetry().WithMetrics(configure).StartWithHost(); return services; } }