Skip to content

Commit

Permalink
Merge pull request #362 from nachoBonafonte/main
Browse files Browse the repository at this point in the history
Allow OTEL_RESOURCE_ATTRIBUTES to be read from main Info.plist file
  • Loading branch information
Ignacio Bonafonte authored Dec 16, 2022
2 parents 93fd1d3 + 5ed1ef3 commit 6fc9920
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/OpenTelemetrySdk/Resources/EnvVarResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6fc9920

Please sign in to comment.