forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzureContainersResourceProvider.java
More file actions
64 lines (48 loc) · 1.96 KB
/
AzureContainersResourceProvider.java
File metadata and controls
64 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.contrib.azure.resource;
import static io.opentelemetry.contrib.azure.resource.IncubatingAttributes.SERVICE_INSTANCE_ID;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
import java.util.HashMap;
import java.util.Map;
public class AzureContainersResourceProvider extends CloudResourceProvider {
static final String CONTAINER_APP_NAME = "CONTAINER_APP_NAME";
private static final String CONTAINER_APP_REPLICA_NAME = "CONTAINER_APP_REPLICA_NAME";
private static final String CONTAINER_APP_REVISION = "CONTAINER_APP_REVISION";
private static final Map<AttributeKey<String>, String> ENV_VAR_MAPPING = new HashMap<>();
static {
ENV_VAR_MAPPING.put(SERVICE_NAME, CONTAINER_APP_NAME);
ENV_VAR_MAPPING.put(SERVICE_INSTANCE_ID, CONTAINER_APP_REPLICA_NAME);
ENV_VAR_MAPPING.put(SERVICE_VERSION, CONTAINER_APP_REVISION);
}
private final Map<String, String> env;
// SPI
public AzureContainersResourceProvider() {
this(System.getenv());
}
// Visible for testing
AzureContainersResourceProvider(Map<String, String> env) {
this.env = env;
}
@Override
public Resource createResource() {
return Resource.create(getAttributes());
}
public Attributes getAttributes() {
AzureEnvVarPlatform detect = AzureEnvVarPlatform.detect(env);
if (detect != AzureEnvVarPlatform.CONTAINER_APP) {
return Attributes.empty();
}
AttributesBuilder builder =
AzureVmResourceProvider.azureAttributeBuilder("azure_container_apps");
AzureEnvVarPlatform.addAttributesFromEnv(ENV_VAR_MAPPING, env, builder);
return builder.build();
}
}