Skip to content

Commit

Permalink
Update azure-monitor-opentelemetry-exporter (#3356)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyams authored Oct 26, 2023
1 parent 3e8eb4e commit e58f62f
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 109 deletions.
2 changes: 1 addition & 1 deletion agent/agent-tooling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation(project(":agent:agent-profiler:agent-diagnostics"))
implementation(project(":etw:java"))

implementation("com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.11")
implementation("com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.13")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
compileOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap")
Expand Down
5 changes: 2 additions & 3 deletions agent/agent-tooling/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ com.azure:azure-core-http-netty:1.13.7=runtimeClasspath
com.azure:azure-core:1.43.0=runtimeClasspath
com.azure:azure-identity:1.10.4=runtimeClasspath
com.azure:azure-json:1.1.0=runtimeClasspath
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.11=runtimeClasspath
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.13=runtimeClasspath
com.azure:azure-sdk-bom:1.2.17=runtimeClasspath
com.azure:azure-storage-blob:12.24.0=runtimeClasspath
com.azure:azure-storage-common:12.23.0=runtimeClasspath
Expand Down Expand Up @@ -67,6 +67,7 @@ io.opentelemetry:opentelemetry-context:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-extension-incubator:1.31.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-common:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-logs:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-metrics:1.31.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-trace:1.31.0=runtimeClasspath
Expand All @@ -80,9 +81,7 @@ net.minidev:accessors-smart:2.4.9=runtimeClasspath
net.minidev:json-smart:2.4.10=runtimeClasspath
org.apache.commons:commons-lang3:3.12.0=runtimeClasspath
org.apache.commons:commons-text:1.10.0=runtimeClasspath
org.awaitility:awaitility:4.2.0=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.1=runtimeClasspath
org.hamcrest:hamcrest:2.1=runtimeClasspath
org.junit:junit-bom:5.10.0=runtimeClasspath
org.reactivestreams:reactive-streams:1.0.4=runtimeClasspath
org.slf4j:jcl-over-slf4j:2.0.9=runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.MINUTES;

import com.azure.monitor.opentelemetry.exporter.implementation.utils.PropertyHelper;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.microsoft.applicationinsights.agent.internal.common.FriendlyException;
Expand Down Expand Up @@ -618,7 +619,7 @@ public static class DestinationFile {
public int maxHistory = 1;

private static String getDefaultPath() {
if (!SdkVersionPrefixHolder.isRpIntegration()) {
if (!PropertyHelper.isRpIntegration()) {
if (isRuntimeAttached()) { // With runtime attachment, the agent jar is located in a temp
// folder that is dropped when the JVM shuts down
String userDir = System.getProperty("user.dir");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;

import com.azure.monitor.opentelemetry.exporter.implementation.statsbeat.RpAttachType;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.PropertyHelper;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.Strings;
import com.microsoft.applicationinsights.agent.internal.configuration.SdkVersionPrefixHolder;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -34,27 +34,27 @@ private DiagnosticsHelper() {}

public static void initRpIntegration(Path agentPath) {
// important to check FUNCTIONS_WORKER_RUNTIME before WEBSITE_SITE_NAME
// TODO (heya) how should we report functions windows users who are using app services
// windows attach by manually setting the env vars (which was the old documented way)
// TODO (heya) refactor PropertyHelper and ResourceProvider to simplify logic for rp
if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) {
SdkVersionPrefixHolder.setRpIntegrationChar('f');
PropertyHelper.setRpIntegrationChar('f');
functionsRpIntegration = true;
setRpAttachType(agentPath, "functions.codeless");
} else if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) {
SdkVersionPrefixHolder.setRpIntegrationChar('a');
PropertyHelper.setRpIntegrationChar('a');
appSvcRpIntegration = true;
setRpAttachType(agentPath, "appsvc.codeless");
} else if (!Strings.isNullOrEmpty(System.getenv("AKS_ARM_NAMESPACE_ID"))) {
// AKS_ARM_NAMESPACE_ID is an env var available in AKS only and it's also used as the AKS
// attach rate numerator
SdkVersionPrefixHolder.setRpIntegrationChar('k');
PropertyHelper.setRpIntegrationChar('k');
setRpAttachType(agentPath, "aks.codeless");
} else if (!Strings.isNullOrEmpty(
System.getenv("APPLICATIONINSIGHTS_SPRINGCLOUD_SERVICE_ID"))) {
SdkVersionPrefixHolder.setRpIntegrationChar('s');
PropertyHelper.setRpIntegrationChar('s');
setRpAttachType(agentPath, "springcloud.codeless");
} else {
RpAttachType.setRpAttachType(RpAttachType.STANDALONE_AUTO); // default
}
// TODO (heya) detect VM environment by checking the AzureMetadataService response, manual only
}

public static boolean isAppSvcRpIntegration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public Map<String, String> apply(ConfigProperties otelConfig) {

enableInstrumentations(otelConfig, configuration, properties);

// enable "io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider" only. It
// enables all resource provider by default
properties.put(
"otel.java.enabled.resource.providers",
"io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider");

if (!configuration.preview.captureControllerSpans) {
properties.put(
"otel.instrumentation.common.experimental.controller-telemetry.enabled", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.microsoft.applicationinsights.agent.internal.configuration.ConfigurationBuilder;
import com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration;
import com.microsoft.applicationinsights.agent.internal.configuration.RpConfigurationBuilder;
import com.microsoft.applicationinsights.agent.internal.configuration.SdkVersionPrefixHolder;
import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsHelper;
import com.microsoft.applicationinsights.agent.internal.diagnostics.PidFinder;
import com.microsoft.applicationinsights.agent.internal.diagnostics.SdkVersionFinder;
Expand Down Expand Up @@ -311,10 +310,10 @@ private static String getCodelessSdkNamePrefix() {
if (isRuntimeAttached()) {
return "ra_";
}
if (!SdkVersionPrefixHolder.isRpIntegration()) {
if (!PropertyHelper.isRpIntegration()) {
return null;
}
return SdkVersionPrefixHolder.getRpIntegrationSdkNamePrefix();
return PropertyHelper.getRpIntegrationSdkNamePrefix();
}

private static boolean isRuntimeAttached() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.azure.monitor.opentelemetry.exporter.implementation.statsbeat.Feature;
import com.azure.monitor.opentelemetry.exporter.implementation.statsbeat.StatsbeatModule;
import com.azure.monitor.opentelemetry.exporter.implementation.statsbeat.StatsbeatTelemetryPipelineListener;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.PropertyHelper;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.Strings;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.TempDirs;
import com.google.auto.service.AutoService;
Expand All @@ -34,7 +35,6 @@
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingTelemetryType;
import com.microsoft.applicationinsights.agent.internal.configuration.ConfigurationBuilder;
import com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration;
import com.microsoft.applicationinsights.agent.internal.configuration.SdkVersionPrefixHolder;
import com.microsoft.applicationinsights.agent.internal.configuration.SnippetConfiguration;
import com.microsoft.applicationinsights.agent.internal.exporter.AgentLogExporter;
import com.microsoft.applicationinsights.agent.internal.exporter.AgentMetricExporter;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
.collect(Collectors.toList());

StatsbeatModule statsbeatModule =
new StatsbeatModule(SdkVersionPrefixHolder::lazyUpdateVmRpIntegration);
new StatsbeatModule(PropertyHelper::lazyUpdateVmRpIntegration);
TelemetryClient telemetryClient =
TelemetryClient.builder()
.setCustomDimensions(configuration.customDimensions)
Expand Down Expand Up @@ -290,7 +290,7 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
private static TelemetryItemExporter initStatsbeatTelemetryItemExporter(
StatsbeatModule statsbeatModule, File tempDir, int diskPersistenceMaxSizeMb) {
HttpPipeline httpPipeline = LazyHttpClient.newHttpPipeLine(null);
TelemetryPipeline telemetryPipeline = new TelemetryPipeline(httpPipeline);
TelemetryPipeline telemetryPipeline = new TelemetryPipeline(httpPipeline, statsbeatModule);

TelemetryPipelineListener telemetryPipelineListener;
if (tempDir == null) {
Expand Down Expand Up @@ -385,12 +385,66 @@ private static Set<Feature> initStatsbeatFeatureSet(Configuration config) {
if (config.preview.browserSdkLoader.enabled) {
featureList.add(Feature.BROWSER_SDK_LOADER);
}

// Statsbeat
if (!config.preview.sampling.overrides.isEmpty()) {
featureList.add(Feature.PREVIEW_SAMPLING);
}
if (config.preview.captureControllerSpans) {
featureList.add(Feature.PREVIEW_CAPTURE_CONTROLLER_SPANS);
}
if (!config.preview.liveMetrics.enabled) {
featureList.add(Feature.PREVIEW_LIVE_METRICS);
}
if (config.preview.legacyRequestIdPropagation.enabled) {
featureList.add(Feature.PREVIEW_LEGACY_REQUEST_ID_PROPAGATION);
}
if (config.preview.disablePropagation) {
featureList.add(Feature.PREVIEW_DISABLE_PROPAGATION);
}
if (config.preview.captureLoggingLevelAsCustomDimension) {
featureList.add(Feature.PREVIEW_CAPTURE_LOGGING_LEVEL_AS_CUSTOM_DIMENSION);
}
if (config.preview.captureLogbackCodeAttributes) {
featureList.add(Feature.PREVIEW_CAPTURE_LOGBACK_CODE_ATTRIBUTES);
}
if (config.preview.captureLogbackMarker) {
featureList.add(Feature.PREVIEW_CAPTURE_LOGBACK_MARKER);
}
if (config.preview.captureLog4jMarker) {
featureList.add(Feature.PREVIEW_CAPTURE_LOG4J_MARKER);
}
if (!config.preview.additionalPropagators.isEmpty()) {
featureList.add(Feature.PREVIEW_ADDITIONAL_PROPAGATORS);
}
if (!config.preview.inheritedAttributes.isEmpty()) {
featureList.add(Feature.PREVIEW_INHERITED_ATTRIBUTES);
}
if (config.preview.gcEvents.reportingLevel != null) {
featureList.add(Feature.PREVIEW_GC_EVENTS);
}
if (!config.preview.connectionStringOverrides.isEmpty()) {
featureList.add(Feature.PREVIEW_CONNECTION_STRING_OVERRIDES);
}
if (!config.preview.roleNameOverrides.isEmpty()) {
featureList.add(Feature.PREVIEW_ROLE_NAME_OVERRIDES);
}
if (config.preview.generalExportQueueCapacity != 2048) {
featureList.add(Feature.PREVIEW_GENERAL_EXPORT_QUEUE_CAPACITY);
}
if (config.preview.metricsExportQueueCapacity != 65536) {
featureList.add(Feature.PREVIEW_METRICS_EXPORT_QUEUE_CAPACITY);
}
if (config.preview.diskPersistenceMaxSizeMb != 50) {
featureList.add(Feature.PREVIEW_DISK_PERSISTENCE_MAX_SIZE_MB);
}
if (!config.preview.useNormalizedValueForNonNormalizedCpuPercentage) {
featureList.add(Feature.PREVIEW_DONT_USE_NORMALIZED);
}
if (!config.preview.customInstrumentation.isEmpty()) {
featureList.add(Feature.PREVIEW_CUSTOM_INSTRUMENTATION);
}
if (config.preview.statsbeat.disabled) {
featureList.add(Feature.STATSBEAT_DISABLED);
}

if (config.preview.disablePropagation) {
featureList.add(Feature.PROPAGATION_DISABLED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.azure.monitor.opentelemetry.exporter.implementation.utils.TempDirs;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration;
import com.microsoft.applicationinsights.agent.internal.httpclient.LazyHttpClient;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.resources.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -227,7 +229,7 @@ private BatchItemProcessor initBatchItemProcessor(
LazyHttpClient.newHttpPipeLine(
aadAuthentication,
new NetworkStatsbeatHttpPipelinePolicy(statsbeatModule.getNetworkStatsbeat()));
TelemetryPipeline telemetryPipeline = new TelemetryPipeline(httpPipeline);
TelemetryPipeline telemetryPipeline = new TelemetryPipeline(httpPipeline, statsbeatModule);

TelemetryPipelineListener telemetryPipelineListener;
if (tempDir == null) {
Expand Down Expand Up @@ -328,14 +330,15 @@ public void populateDefaults(AbstractTelemetryBuilder telemetryBuilder, Resource
// not sure if connectionString can be null in Azure Functions
telemetryBuilder.setConnectionString(connectionString);
}
telemetryBuilder.setResource(resource);
for (Map.Entry<String, String> entry : globalTags.entrySet()) {
telemetryBuilder.addTag(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : globalProperties.entrySet()) {
telemetryBuilder.addProperty(entry.getKey(), entry.getValue());
}
ResourceParser.updateRoleNameAndInstance(
telemetryBuilder, resource, com.azure.core.util.Configuration.getGlobalConfiguration());
telemetryBuilder, resource, DefaultConfigProperties.create(Collections.emptyMap()));
}

@Nullable
Expand Down
Loading

0 comments on commit e58f62f

Please sign in to comment.