LCOV - code coverage report
Current view: top level - lib/src/environment - env_from_define.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 77 77
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              : 
       4              : import 'env_constants.dart';
       5              : 
       6              : /// Helper function to retrieve String.fromEnvironment values.
       7              : ///
       8              : /// Since String.fromEnvironment requires compile-time constants, we must
       9              : /// explicitly check each possible variable in a switch statement.
      10              : ///
      11              : /// @param key The environment variable name
      12              : /// @return The value from String.fromEnvironment, or null if empty
      13          129 : String? getFromEnvironment(String key) {
      14              :   // We use a switch statement because String.fromEnvironment requires
      15              :   // compile-time constants. Each case must be explicitly listed.
      16              :   switch (key) {
      17              :     // General SDK Configuration
      18          129 :     case otelSdkDisabled:
      19              :       return const String.fromEnvironment(otelSdkDisabled);
      20          129 :     case otelResourceAttributes:
      21              :       return const String.fromEnvironment(otelResourceAttributes);
      22          129 :     case otelServiceName:
      23              :       return const String.fromEnvironment(otelServiceName);
      24          129 :     case otelLogLevel:
      25              :       return const String.fromEnvironment(otelLogLevel);
      26          129 :     case otelPropagators:
      27              :       return const String.fromEnvironment(otelPropagators);
      28          129 :     case otelTracesSampler:
      29              :       return const String.fromEnvironment(otelTracesSampler);
      30          129 :     case otelTracesSamplerArg:
      31              :       return const String.fromEnvironment(otelTracesSamplerArg);
      32              : 
      33              :     // Logging Configuration
      34          129 :     case otelLogMetrics:
      35              :       return const String.fromEnvironment(otelLogMetrics);
      36          129 :     case otelLogSpans:
      37              :       return const String.fromEnvironment(otelLogSpans);
      38          129 :     case otelLogExport:
      39              :       return const String.fromEnvironment(otelLogExport);
      40              : 
      41              :     // General OTLP Configuration
      42          129 :     case otelExporterOtlpEndpoint:
      43              :       return const String.fromEnvironment(otelExporterOtlpEndpoint);
      44          129 :     case otelExporterOtlpProtocol:
      45              :       return const String.fromEnvironment(otelExporterOtlpProtocol);
      46          129 :     case otelExporterOtlpHeaders:
      47              :       return const String.fromEnvironment(otelExporterOtlpHeaders);
      48          129 :     case otelExporterOtlpInsecure:
      49              :       return const String.fromEnvironment(otelExporterOtlpInsecure);
      50          129 :     case otelExporterOtlpTimeout:
      51              :       return const String.fromEnvironment(otelExporterOtlpTimeout);
      52          129 :     case otelExporterOtlpCompression:
      53              :       return const String.fromEnvironment(otelExporterOtlpCompression);
      54          129 :     case otelExporterOtlpCertificate:
      55              :       return const String.fromEnvironment(otelExporterOtlpCertificate);
      56          129 :     case otelExporterOtlpClientKey:
      57              :       return const String.fromEnvironment(otelExporterOtlpClientKey);
      58          129 :     case otelExporterOtlpClientCertificate:
      59              :       return const String.fromEnvironment(otelExporterOtlpClientCertificate);
      60              : 
      61              :     // Traces-specific Configuration
      62          129 :     case otelTracesExporter:
      63              :       return const String.fromEnvironment(otelTracesExporter);
      64          129 :     case otelExporterOtlpTracesEndpoint:
      65              :       return const String.fromEnvironment(otelExporterOtlpTracesEndpoint);
      66          129 :     case otelExporterOtlpTracesProtocol:
      67              :       return const String.fromEnvironment(otelExporterOtlpTracesProtocol);
      68          129 :     case otelExporterOtlpTracesHeaders:
      69              :       return const String.fromEnvironment(otelExporterOtlpTracesHeaders);
      70          129 :     case otelExporterOtlpTracesInsecure:
      71              :       return const String.fromEnvironment(otelExporterOtlpTracesInsecure);
      72          129 :     case otelExporterOtlpTracesTimeout:
      73              :       return const String.fromEnvironment(otelExporterOtlpTracesTimeout);
      74          129 :     case otelExporterOtlpTracesCompression:
      75              :       return const String.fromEnvironment(otelExporterOtlpTracesCompression);
      76          129 :     case otelExporterOtlpTracesCertificate:
      77              :       return const String.fromEnvironment(otelExporterOtlpTracesCertificate);
      78          129 :     case otelExporterOtlpTracesClientKey:
      79              :       return const String.fromEnvironment(otelExporterOtlpTracesClientKey);
      80          129 :     case otelExporterOtlpTracesClientCertificate:
      81              :       return const String.fromEnvironment(
      82              :         otelExporterOtlpTracesClientCertificate,
      83              :       );
      84              : 
      85              :     // Metrics-specific Configuration
      86          129 :     case otelMetricsExporter:
      87              :       return const String.fromEnvironment(otelMetricsExporter);
      88          129 :     case otelExporterOtlpMetricsEndpoint:
      89              :       return const String.fromEnvironment(otelExporterOtlpMetricsEndpoint);
      90          129 :     case otelExporterOtlpMetricsProtocol:
      91              :       return const String.fromEnvironment(otelExporterOtlpMetricsProtocol);
      92          129 :     case otelExporterOtlpMetricsHeaders:
      93              :       return const String.fromEnvironment(otelExporterOtlpMetricsHeaders);
      94          129 :     case otelExporterOtlpMetricsInsecure:
      95              :       return const String.fromEnvironment(otelExporterOtlpMetricsInsecure);
      96          129 :     case otelExporterOtlpMetricsTimeout:
      97              :       return const String.fromEnvironment(otelExporterOtlpMetricsTimeout);
      98          129 :     case otelExporterOtlpMetricsCompression:
      99              :       return const String.fromEnvironment(otelExporterOtlpMetricsCompression);
     100          129 :     case otelExporterOtlpMetricsCertificate:
     101              :       return const String.fromEnvironment(otelExporterOtlpMetricsCertificate);
     102          129 :     case otelExporterOtlpMetricsClientKey:
     103              :       return const String.fromEnvironment(otelExporterOtlpMetricsClientKey);
     104          129 :     case otelExporterOtlpMetricsClientCertificate:
     105              :       return const String.fromEnvironment(
     106              :         otelExporterOtlpMetricsClientCertificate,
     107              :       );
     108              : 
     109              :     // Logs-specific Configuration
     110          119 :     case otelLogsExporter:
     111              :       return const String.fromEnvironment(otelLogsExporter);
     112          119 :     case otelExporterOtlpLogsEndpoint:
     113              :       return const String.fromEnvironment(otelExporterOtlpLogsEndpoint);
     114          119 :     case otelExporterOtlpLogsProtocol:
     115              :       return const String.fromEnvironment(otelExporterOtlpLogsProtocol);
     116          119 :     case otelExporterOtlpLogsHeaders:
     117              :       return const String.fromEnvironment(otelExporterOtlpLogsHeaders);
     118          119 :     case otelExporterOtlpLogsInsecure:
     119              :       return const String.fromEnvironment(otelExporterOtlpLogsInsecure);
     120          119 :     case otelExporterOtlpLogsTimeout:
     121              :       return const String.fromEnvironment(otelExporterOtlpLogsTimeout);
     122          119 :     case otelExporterOtlpLogsCompression:
     123              :       return const String.fromEnvironment(otelExporterOtlpLogsCompression);
     124          119 :     case otelExporterOtlpLogsCertificate:
     125              :       return const String.fromEnvironment(otelExporterOtlpLogsCertificate);
     126          119 :     case otelExporterOtlpLogsClientKey:
     127              :       return const String.fromEnvironment(otelExporterOtlpLogsClientKey);
     128          119 :     case otelExporterOtlpLogsClientCertificate:
     129              :       return const String.fromEnvironment(
     130              :         otelExporterOtlpLogsClientCertificate,
     131              :       );
     132              : 
     133              :     // Batch Span Processor
     134          118 :     case otelBspScheduleDelay:
     135              :       return const String.fromEnvironment(otelBspScheduleDelay);
     136          118 :     case otelBspExportTimeout:
     137              :       return const String.fromEnvironment(otelBspExportTimeout);
     138          118 :     case otelBspMaxQueueSize:
     139              :       return const String.fromEnvironment(otelBspMaxQueueSize);
     140          118 :     case otelBspMaxExportBatchSize:
     141              :       return const String.fromEnvironment(otelBspMaxExportBatchSize);
     142              : 
     143              :     // Batch LogRecord Processor
     144          118 :     case otelBlrpScheduleDelay:
     145              :       return const String.fromEnvironment(otelBlrpScheduleDelay);
     146          118 :     case otelBlrpExportTimeout:
     147              :       return const String.fromEnvironment(otelBlrpExportTimeout);
     148          118 :     case otelBlrpMaxQueueSize:
     149              :       return const String.fromEnvironment(otelBlrpMaxQueueSize);
     150          118 :     case otelBlrpMaxExportBatchSize:
     151              :       return const String.fromEnvironment(otelBlrpMaxExportBatchSize);
     152              : 
     153              :     // Attribute Limits
     154            3 :     case otelAttributeValueLengthLimit:
     155              :       return const String.fromEnvironment(otelAttributeValueLengthLimit);
     156            3 :     case otelAttributeCountLimit:
     157              :       return const String.fromEnvironment(otelAttributeCountLimit);
     158              : 
     159              :     // Span Limits
     160            3 :     case otelSpanAttributeValueLengthLimit:
     161              :       return const String.fromEnvironment(otelSpanAttributeValueLengthLimit);
     162            3 :     case otelSpanAttributeCountLimit:
     163              :       return const String.fromEnvironment(otelSpanAttributeCountLimit);
     164            3 :     case otelSpanEventCountLimit:
     165              :       return const String.fromEnvironment(otelSpanEventCountLimit);
     166            3 :     case otelSpanLinkCountLimit:
     167              :       return const String.fromEnvironment(otelSpanLinkCountLimit);
     168            3 :     case otelEventAttributeCountLimit:
     169              :       return const String.fromEnvironment(otelEventAttributeCountLimit);
     170            3 :     case otelLinkAttributeCountLimit:
     171              :       return const String.fromEnvironment(otelLinkAttributeCountLimit);
     172              : 
     173              :     // LogRecord Limits
     174            3 :     case otelLogrecordAttributeValueLengthLimit:
     175              :       return const String.fromEnvironment(
     176              :         otelLogrecordAttributeValueLengthLimit,
     177              :       );
     178            3 :     case otelLogrecordAttributeCountLimit:
     179              :       return const String.fromEnvironment(otelLogrecordAttributeCountLimit);
     180              : 
     181              :     // Metrics SDK Configuration
     182            1 :     case otelMetricsExemplarFilter:
     183              :       return const String.fromEnvironment(otelMetricsExemplarFilter);
     184            1 :     case otelMetricExportInterval:
     185              :       return const String.fromEnvironment(otelMetricExportInterval);
     186            1 :     case otelMetricExportTimeout:
     187              :       return const String.fromEnvironment(otelMetricExportTimeout);
     188              : 
     189              :     // Zipkin Exporter
     190            1 :     case otelExporterZipkinEndpoint:
     191              :       return const String.fromEnvironment(otelExporterZipkinEndpoint);
     192            1 :     case otelExporterZipkinTimeout:
     193              :       return const String.fromEnvironment(otelExporterZipkinTimeout);
     194              : 
     195              :     // Prometheus Exporter
     196            1 :     case otelExporterPrometheusHost:
     197              :       return const String.fromEnvironment(otelExporterPrometheusHost);
     198            1 :     case otelExporterPrometheusPort:
     199              :       return const String.fromEnvironment(otelExporterPrometheusPort);
     200              : 
     201              :     // Deprecated but supported
     202            1 :     case otelExporterOtlpSpanInsecure:
     203              :       return const String.fromEnvironment(otelExporterOtlpSpanInsecure);
     204            1 :     case otelExporterOtlpMetricInsecure:
     205              :       return const String.fromEnvironment(otelExporterOtlpMetricInsecure);
     206              : 
     207              :     default:
     208              :       return null;
     209              :   }
     210              : }
        

Generated by: LCOV version 2.0-1