Skip to content

Commit 534f401

Browse files
heyamszeitlinger
authored andcommitted
Fix deprecated ResourceAttributes
1 parent f54a88b commit 534f401

File tree

6 files changed

+59
-38
lines changed

6 files changed

+59
-38
lines changed

azure-resources/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ dependencies {
1717
api("io.opentelemetry:opentelemetry-api")
1818
api("io.opentelemetry:opentelemetry-sdk")
1919

20-
// Provides GCP resource detection support
21-
// implementation("com.google.cloud.opentelemetry:detector-resources-support:0.27.0")
22-
23-
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
20+
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
2421

2522
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
2623

azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureAppServiceResourceProvider.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55

66
package io.opentelemetry.contrib.azure.resource;
77

8+
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
9+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_REGION;
10+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID;
11+
import static io.opentelemetry.semconv.incubating.DeploymentIncubatingAttributes.DEPLOYMENT_ENVIRONMENT;
12+
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_ID;
13+
import static io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes.SERVICE_INSTANCE_ID;
14+
815
import io.opentelemetry.api.common.AttributeKey;
916
import io.opentelemetry.api.common.Attributes;
1017
import io.opentelemetry.api.common.AttributesBuilder;
1118
import io.opentelemetry.api.internal.StringUtils;
1219
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1320
import io.opentelemetry.sdk.resources.Resource;
14-
import io.opentelemetry.semconv.ResourceAttributes;
21+
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
1522
import java.util.HashMap;
1623
import java.util.Map;
1724
import java.util.Objects;
@@ -33,10 +40,10 @@ public class AzureAppServiceResourceProvider extends CloudResourceProvider {
3340
private static final Map<AttributeKey<String>, String> ENV_VAR_MAPPING = new HashMap<>();
3441

3542
static {
36-
ENV_VAR_MAPPING.put(ResourceAttributes.CLOUD_REGION, REGION_NAME);
37-
ENV_VAR_MAPPING.put(ResourceAttributes.DEPLOYMENT_ENVIRONMENT, WEBSITE_SLOT_NAME);
38-
ENV_VAR_MAPPING.put(ResourceAttributes.HOST_ID, WEBSITE_HOSTNAME);
39-
ENV_VAR_MAPPING.put(ResourceAttributes.SERVICE_INSTANCE_ID, WEBSITE_INSTANCE_ID);
43+
ENV_VAR_MAPPING.put(CLOUD_REGION, REGION_NAME);
44+
ENV_VAR_MAPPING.put(DEPLOYMENT_ENVIRONMENT, WEBSITE_SLOT_NAME);
45+
ENV_VAR_MAPPING.put(HOST_ID, WEBSITE_HOSTNAME);
46+
ENV_VAR_MAPPING.put(SERVICE_INSTANCE_ID, WEBSITE_INSTANCE_ID);
4047
ENV_VAR_MAPPING.put(AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE, WEBSITE_HOME_STAMPNAME);
4148
}
4249

@@ -65,12 +72,12 @@ public Attributes getAttributes() {
6572
String name = Objects.requireNonNull(env.get(WEBSITE_SITE_NAME));
6673
AttributesBuilder builder =
6774
AzureVmResourceProvider.azureAttributeBuilder(
68-
ResourceAttributes.CloudPlatformValues.AZURE_APP_SERVICE);
69-
builder.put(ResourceAttributes.SERVICE_NAME, name);
75+
CloudIncubatingAttributes.CloudPlatformValues.AZURE_APP_SERVICE);
76+
builder.put(SERVICE_NAME, name);
7077

7178
String resourceUri = resourceUri(name);
7279
if (resourceUri != null) {
73-
builder.put(ResourceAttributes.CLOUD_RESOURCE_ID, resourceUri);
80+
builder.put(CLOUD_RESOURCE_ID, resourceUri);
7481
}
7582

7683
AzureEnvVarPlatform.addAttributesFromEnv(ENV_VAR_MAPPING, env, builder);

azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureContainersResourceProvider.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
package io.opentelemetry.contrib.azure.resource;
77

8+
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
9+
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
10+
import static io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes.SERVICE_INSTANCE_ID;
11+
812
import io.opentelemetry.api.common.AttributeKey;
913
import io.opentelemetry.api.common.Attributes;
1014
import io.opentelemetry.api.common.AttributesBuilder;
1115
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1216
import io.opentelemetry.sdk.resources.Resource;
13-
import io.opentelemetry.semconv.ResourceAttributes;
1417
import java.util.HashMap;
1518
import java.util.Map;
1619

@@ -24,9 +27,9 @@ public class AzureContainersResourceProvider extends CloudResourceProvider {
2427
private static final Map<AttributeKey<String>, String> ENV_VAR_MAPPING = new HashMap<>();
2528

2629
static {
27-
ENV_VAR_MAPPING.put(ResourceAttributes.SERVICE_NAME, CONTAINER_APP_NAME);
28-
ENV_VAR_MAPPING.put(ResourceAttributes.SERVICE_INSTANCE_ID, CONTAINER_APP_REPLICA_NAME);
29-
ENV_VAR_MAPPING.put(ResourceAttributes.SERVICE_VERSION, CONTAINER_APP_REVISION);
30+
ENV_VAR_MAPPING.put(SERVICE_NAME, CONTAINER_APP_NAME);
31+
ENV_VAR_MAPPING.put(SERVICE_INSTANCE_ID, CONTAINER_APP_REPLICA_NAME);
32+
ENV_VAR_MAPPING.put(SERVICE_VERSION, CONTAINER_APP_REVISION);
3033
}
3134

3235
private final Map<String, String> env;

azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureFunctionsResourceProvider.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
package io.opentelemetry.contrib.azure.resource;
77

8+
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INSTANCE;
9+
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_MAX_MEMORY;
10+
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_NAME;
11+
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_VERSION;
12+
813
import io.opentelemetry.api.common.AttributeKey;
914
import io.opentelemetry.api.common.Attributes;
1015
import io.opentelemetry.api.common.AttributesBuilder;
1116
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1217
import io.opentelemetry.sdk.resources.Resource;
13-
import io.opentelemetry.semconv.ResourceAttributes;
18+
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
1419
import java.util.HashMap;
1520
import java.util.Map;
1621

@@ -23,12 +28,10 @@ public class AzureFunctionsResourceProvider extends CloudResourceProvider {
2328

2429
static {
2530
ENV_VAR_MAPPING.put(
26-
ResourceAttributes.CLOUD_REGION, AzureAppServiceResourceProvider.REGION_NAME);
27-
ENV_VAR_MAPPING.put(
28-
ResourceAttributes.FAAS_NAME, AzureAppServiceResourceProvider.WEBSITE_SITE_NAME);
29-
ENV_VAR_MAPPING.put(ResourceAttributes.FAAS_VERSION, FUNCTIONS_VERSION);
30-
ENV_VAR_MAPPING.put(
31-
ResourceAttributes.FAAS_INSTANCE, AzureAppServiceResourceProvider.WEBSITE_INSTANCE_ID);
31+
CloudIncubatingAttributes.CLOUD_REGION, AzureAppServiceResourceProvider.REGION_NAME);
32+
ENV_VAR_MAPPING.put(FAAS_NAME, AzureAppServiceResourceProvider.WEBSITE_SITE_NAME);
33+
ENV_VAR_MAPPING.put(FAAS_VERSION, FUNCTIONS_VERSION);
34+
ENV_VAR_MAPPING.put(FAAS_INSTANCE, AzureAppServiceResourceProvider.WEBSITE_INSTANCE_ID);
3235
}
3336

3437
private final Map<String, String> env;
@@ -56,11 +59,11 @@ public Attributes getAttributes() {
5659

5760
AttributesBuilder builder =
5861
AzureVmResourceProvider.azureAttributeBuilder(
59-
ResourceAttributes.CloudPlatformValues.AZURE_FUNCTIONS);
62+
CloudIncubatingAttributes.CloudPlatformValues.AZURE_FUNCTIONS);
6063

6164
String limit = env.get(FUNCTIONS_MEM_LIMIT);
6265
if (limit != null) {
63-
builder.put(ResourceAttributes.FAAS_MAX_MEMORY, Long.parseLong(limit));
66+
builder.put(FAAS_MAX_MEMORY, Long.parseLong(limit));
6467
}
6568

6669
AzureEnvVarPlatform.addAttributesFromEnv(ENV_VAR_MAPPING, env, builder);

azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureVmResourceProvider.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
package io.opentelemetry.contrib.azure.resource;
77

8+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
9+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
10+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_REGION;
11+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID;
12+
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_ID;
13+
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_NAME;
14+
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_TYPE;
15+
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_TYPE;
16+
import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_VERSION;
17+
818
import com.fasterxml.jackson.core.JsonFactory;
919
import com.fasterxml.jackson.core.JsonParser;
1020
import com.fasterxml.jackson.core.JsonToken;
@@ -13,7 +23,7 @@
1323
import io.opentelemetry.api.common.AttributesBuilder;
1424
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1525
import io.opentelemetry.sdk.resources.Resource;
16-
import io.opentelemetry.semconv.ResourceAttributes;
26+
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
1727
import java.io.IOException;
1828
import java.net.MalformedURLException;
1929
import java.net.URL;
@@ -36,13 +46,13 @@ public class AzureVmResourceProvider extends CloudResourceProvider {
3646
private static final Map<String, AttributeKey<String>> COMPUTE_MAPPING = new HashMap<>();
3747

3848
static {
39-
COMPUTE_MAPPING.put("location", ResourceAttributes.CLOUD_REGION);
40-
COMPUTE_MAPPING.put("resourceId", ResourceAttributes.CLOUD_RESOURCE_ID);
41-
COMPUTE_MAPPING.put("vmId", ResourceAttributes.HOST_ID);
42-
COMPUTE_MAPPING.put("name", ResourceAttributes.HOST_NAME);
43-
COMPUTE_MAPPING.put("vmSize", ResourceAttributes.HOST_TYPE);
44-
COMPUTE_MAPPING.put("osType", ResourceAttributes.OS_TYPE);
45-
COMPUTE_MAPPING.put("version", ResourceAttributes.OS_VERSION);
49+
COMPUTE_MAPPING.put("location", CLOUD_REGION);
50+
COMPUTE_MAPPING.put("resourceId", CLOUD_RESOURCE_ID);
51+
COMPUTE_MAPPING.put("vmId", HOST_ID);
52+
COMPUTE_MAPPING.put("name", HOST_NAME);
53+
COMPUTE_MAPPING.put("vmSize", HOST_TYPE);
54+
COMPUTE_MAPPING.put("osType", OS_TYPE);
55+
COMPUTE_MAPPING.put("version", OS_VERSION);
4656
COMPUTE_MAPPING.put("vmScaleSetName", AttributeKey.stringKey("azure.vm.scaleset.name"));
4757
COMPUTE_MAPPING.put("sku", AttributeKey.stringKey("azure.vm.sku"));
4858
}
@@ -87,7 +97,7 @@ public Resource createResource(ConfigProperties config) {
8797

8898
private static Resource parseMetadata(String body) {
8999
AttributesBuilder builder =
90-
azureAttributeBuilder(ResourceAttributes.CloudPlatformValues.AZURE_VM);
100+
azureAttributeBuilder(CloudIncubatingAttributes.CloudPlatformValues.AZURE_VM);
91101
try (JsonParser parser = JSON_FACTORY.createParser(body)) {
92102
parser.nextToken();
93103
parseResponse(parser, builder);
@@ -100,8 +110,8 @@ private static Resource parseMetadata(String body) {
100110
@NotNull
101111
static AttributesBuilder azureAttributeBuilder(String platform) {
102112
AttributesBuilder builder = Attributes.builder();
103-
builder.put(ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AZURE);
104-
builder.put(ResourceAttributes.CLOUD_PLATFORM, platform);
113+
builder.put(CLOUD_PROVIDER, CloudIncubatingAttributes.CloudProviderValues.AZURE);
114+
builder.put(CLOUD_PLATFORM, platform);
105115
return builder;
106116
}
107117

azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/CloudResourceProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
package io.opentelemetry.contrib.azure.resource;
77

8+
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PROVIDER;
9+
810
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
911
import io.opentelemetry.sdk.autoconfigure.spi.internal.ConditionalResourceProvider;
1012
import io.opentelemetry.sdk.resources.Resource;
11-
import io.opentelemetry.semconv.ResourceAttributes;
1213

1314
public abstract class CloudResourceProvider implements ConditionalResourceProvider {
1415

1516
@Override
1617
public final boolean shouldApply(ConfigProperties config, Resource existing) {
17-
return existing.getAttribute(ResourceAttributes.CLOUD_PROVIDER) == null;
18+
return existing.getAttribute(CLOUD_PROVIDER) == null;
1819
}
1920
}

0 commit comments

Comments
 (0)