From 4fb8d81b9a0c7c3980b1bd2814dfcded9813ec36 Mon Sep 17 00:00:00 2001 From: Nacho Bonafonte Date: Thu, 15 Dec 2022 17:54:25 +0100 Subject: [PATCH] Allow OC_RESOURCE_LABELS to be read from main Info.plist file if environment variable is not set --- Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift b/Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift index 54e18c8e..bea03328 100644 --- a/Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift +++ b/Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift @@ -13,12 +13,15 @@ public struct EnvVarResource { private static let labelKeyValueSplitter = Character("=") /// This resource information is loaded from the OC_RESOURCE_LABELS - /// environment variable. + /// environment variable or from the Info.plist file of the application loading the framework. public static let resource = Resource().merging(other: Resource(attributes: parseResourceAttributes(rawEnvAttributes: ProcessInfo.processInfo.environment[otelResourceAttributesEnv]))) private init() {} public static func get(environment: [String: String] = ProcessInfo.processInfo.environment) -> Resource { - return Resource().merging(other: Resource(attributes: parseResourceAttributes(rawEnvAttributes: environment[otelResourceAttributesEnv]))) + let attributesToRead = environment[otelResourceAttributesEnv] ?? + Bundle.main.infoDictionary?[otelResourceAttributesEnv] as? String + + return Resource().merging(other: Resource(attributes: parseResourceAttributes(rawEnvAttributes: attributesToRead))) } /// Creates a label map from the OC_RESOURCE_LABELS environment variable.