getServiceConfig static method

ServiceEnvironmentValues getServiceConfig()

Implementation

static ServiceEnvironmentValues getServiceConfig() {
  String? parsedServiceName;
  String? parsedServiceVersion;

  // First, parse service.name and service.version from OTEL_RESOURCE_ATTRIBUTES
  final resourceStr = _getEnv(otelResourceAttributes);
  if (resourceStr != null) {
    final attrs = parseResourceAttributesString(resourceStr);
    parsedServiceName = attrs[Service.serviceName.key];
    parsedServiceVersion = attrs[Service.serviceVersion.key];
  }

  // OTEL_SERVICE_NAME takes precedence over service.name from resource attributes
  final serviceName = _getEnv(otelServiceName);
  if (serviceName != null) {
    parsedServiceName = serviceName;
  }

  return (
    serviceName: parsedServiceName,
    serviceVersion: parsedServiceVersion,
  );
}