LCOV - code coverage report
Current view: top level - lib/src/factory - otel_sdk_factory.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.2 % 17 15
Test Date: 2026-07-11 13:35:19 Functions: - 0 0

            Line data    Source code
       1              : // Copyright The OpenTelemetry Authors
       2              : // SPDX-License-Identifier: Apache-2.0
       3              : import 'package:dartastic_opentelemetry_api/dartastic_opentelemetry_api.dart';
       4              : 
       5              : import '../logs/logger_provider.dart';
       6              : import '../metrics/meter_provider.dart';
       7              : import '../resource/resource.dart';
       8              : import '../trace/tracer_provider.dart';
       9              : 
      10              : /// Factory function that creates an OTelSDKFactory with the specified configuration.
      11              : ///
      12              : /// Application developers should use the OTel class to create object, which uses this factory.
      13              : /// This function serves as the default factory for creating OTelSDKFactory instances.
      14              : /// It encapsulates the creation logic for the factory to make it simpler to create
      15              : /// properly configured instances.
      16              : ///
      17              : /// @param apiEndpoint The endpoint URL for the OpenTelemetry collector
      18              : /// @param apiServiceName The name of the service being instrumented
      19              : /// @param apiServiceVersion The version of the service being instrumented
      20              : /// @return A configured OTelSDKFactory instance
      21          128 : OTelFactory otelSDKFactoryFactoryFunction({
      22              :   required String apiEndpoint,
      23              :   required String apiServiceName,
      24              :   required String apiServiceVersion,
      25              : }) {
      26          128 :   return OTelSDKFactory(
      27              :     apiEndpoint: apiEndpoint,
      28              :     apiServiceName: apiServiceName,
      29              :     apiServiceVersion: apiServiceVersion,
      30              :   );
      31              : }
      32              : 
      33              : /// Factory implementation for creating OpenTelemetry SDK objects.
      34              : ///
      35              : /// The OTelSDKFactory extends the API factory to provide implementations
      36              : /// of SDK-specific objects and override API object creation to use SDK implementations.
      37              : /// This factory is the primary entry point for creating OpenTelemetry objects in the SDK.
      38              : ///
      39              : /// The OpenTelemetry specification requires the API to work without an SDK installed.
      40              : /// When the SDK is installed, this factory replaces the API's factory to provide
      41              : /// concrete implementations instead of no-op implementations.
      42              : class OTelSDKFactory extends OTelAPIFactory {
      43              :   /// Creates a new OTelSDKFactory with the specified configuration.
      44              :   ///
      45              :   /// @param apiEndpoint The endpoint URL for the OpenTelemetry collector
      46              :   /// @param apiServiceName The name of the service being instrumented
      47              :   /// @param apiServiceVersion The version of the service being instrumented
      48              :   /// @param factoryFactory Optional factory function for creating new instances
      49          128 :   OTelSDKFactory({
      50              :     required super.apiEndpoint,
      51              :     required super.apiServiceName,
      52              :     required super.apiServiceVersion,
      53              :     super.factoryFactory = otelSDKFactoryFactoryFunction,
      54              :   });
      55              : 
      56            4 :   @override
      57              :   bool get isAPIFactory => false;
      58              : 
      59              :   /// Creates a new Resource with the specified attributes and schema URL.
      60              :   ///
      61              :   /// Resources are immutable collections of attributes that describe the entity
      62              :   /// producing telemetry. They are an SDK concept that's not present in the API.
      63              :   ///
      64              :   /// @param attributes The attributes describing the resource
      65              :   /// @param schemaUrl Optional schema URL for the resource attributes
      66              :   /// @return A new Resource instance with the provided attributes
      67          128 :   Resource resource(Attributes attributes, [String? schemaUrl]) {
      68          128 :     return ResourceCreate.create(attributes, schemaUrl);
      69              :   }
      70              : 
      71              :   /// Creates an empty resource with no attributes.
      72              :   ///
      73              :   /// This is a convenience method for quickly creating an empty resource
      74              :   /// when no resource attributes are needed.
      75              :   ///
      76              :   /// @return A new empty Resource instance
      77            0 :   Resource resourceEmpty() {
      78            0 :     return resource(attributesFromMap({}), null);
      79              :   }
      80              : 
      81              :   /// Creates a TracerProvider with the specified configuration.
      82              :   ///
      83              :   /// This implementation overrides the API's method to create an SDK TracerProvider
      84              :   /// that produces real traces instead of no-op traces.
      85              :   ///
      86              :   /// @param endpoint The endpoint URL for the OpenTelemetry collector
      87              :   /// @param serviceName The name of the service being instrumented
      88              :   /// @param serviceVersion The version of the service being instrumented
      89              :   /// @param resource Optional resource describing the service
      90              :   /// @return A configured TracerProvider instance
      91          128 :   @override
      92              :   APITracerProvider tracerProvider({
      93              :     required String endpoint,
      94              :     String serviceName =
      95              :         '@dart/opentelemetry_api', //TODO - @dart/dartastic_opentelemetry
      96              :     String? serviceVersion,
      97              :     Resource? resource,
      98              :   }) {
      99          128 :     return SDKTracerProviderCreate.create(
     100          128 :       delegate: super.tracerProvider(
     101              :         endpoint: endpoint,
     102              :         serviceVersion: serviceVersion,
     103              :         serviceName: serviceName,
     104              :       ),
     105              :       resource: resource,
     106              :     );
     107              :   }
     108              : 
     109              :   /// Creates a MeterProvider with the specified configuration.
     110              :   ///
     111              :   /// This implementation overrides the API's method to create an SDK MeterProvider
     112              :   /// that produces real metrics instead of no-op metrics.
     113              :   ///
     114              :   /// @param endpoint The endpoint URL for the OpenTelemetry collector
     115              :   /// @param serviceName The name of the service being instrumented
     116              :   /// @param serviceVersion The version of the service being instrumented
     117              :   /// @param resource Optional resource describing the service
     118              :   /// @return A configured MeterProvider instance
     119          121 :   @override
     120              :   APIMeterProvider meterProvider({
     121              :     required String endpoint,
     122              :     String serviceName = '@dart/opentelemetry_api',
     123              :     String? serviceVersion,
     124              :     Resource? resource,
     125              :   }) {
     126          121 :     return SDKMeterProviderCreate.create(
     127          121 :       delegate: super.meterProvider(
     128              :         endpoint: endpoint,
     129              :         serviceVersion: serviceVersion,
     130              :         serviceName: serviceName,
     131              :       ),
     132              :       resource: resource,
     133              :     );
     134              :   }
     135              : 
     136              :   /// Creates a LoggerProvider with the specified configuration.
     137              :   ///
     138              :   /// This implementation overrides the API's method to create an SDK LoggerProvider
     139              :   /// that produces real logs instead of no-op logs.
     140              :   ///
     141              :   /// @param endpoint The endpoint URL for the OpenTelemetry collector
     142              :   /// @param serviceName The name of the service being instrumented
     143              :   /// @param serviceVersion The version of the service being instrumented
     144              :   /// @param resource Optional resource describing the service
     145              :   /// @return A configured LoggerProvider instance
     146          120 :   @override
     147              :   APILoggerProvider loggerProvider(
     148              :       {required String endpoint,
     149              :       String serviceName = '@dart/opentelemetry_api',
     150              :       String? serviceVersion,
     151              :       Resource? resource}) {
     152          120 :     return SDKLoggerProviderCreate.create(
     153          120 :         delegate: super.loggerProvider(
     154              :             endpoint: endpoint,
     155              :             serviceVersion: serviceVersion,
     156              :             serviceName: serviceName),
     157              :         resource: resource);
     158              :   }
     159              : }
        

Generated by: LCOV version 2.0-1