Skip to content

Commit

Permalink
Ability to display exported data
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti committed Dec 2, 2024
1 parent 8d0a0d6 commit ecbfe54
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
import com.azure.json.JsonProviders;
import com.azure.json.JsonReader;
import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporterOptions;
import com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.SelfDiagnosticsLevel;
import com.azure.monitor.opentelemetry.exporter.implementation.models.*;
import io.opentelemetry.sdk.common.internal.OtelVersion;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import reactor.util.annotation.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -64,12 +61,6 @@ HttpPipeline getHttpPipeline(@Nullable HttpPipelinePolicy policy) {
.policies(policy)
.build();
}

@Bean
@Primary
SelfDiagnosticsLevel testSelfDiagnosticsLevel() {
return SelfDiagnosticsLevel.DEBUG;
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation;
package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Default self-diagnostics features for logging when Logback is not found.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingClass({"ch.qos.logback.classic.LoggerContext"})
public class DefaultLogConfig {
class DefaultLogConfig {

/**
* To define a logger for self-diagnostics.
*
* @return A logger for self-diagnostics
*/
@Bean
public Logger selfDiagnosticsLogger() {
Logger selfDiagnosticsLogger() {
Logger logger = LoggerFactory.getLogger(SelfDiagnostics.class);
String selfDiagLevelDefinedByUser = System.getenv(SelfDiagAutoConfig.SELF_DIAGNOSTICS_LEVEL_ENV_VAR);
if (selfDiagLevelDefinedByUser != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation;
package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

import org.slf4j.Logger;
import org.springframework.boot.CommandLineRunner;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ch.qos.logback.classic.LoggerContext.class)
class LogbackSelfDiagConfig {

@Bean
Logger selfDiagnosticsLogger(SelfDiagnosticsLevel selfDiagnosticsLevel) {
Logger slf4jLog = LoggerFactory.getLogger(SelfDiagnostics.class);
ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) slf4jLog;
Level logbackLevel = Level.toLevel(selfDiagnosticsLevel.name());
logbackLogger.setLevel(logbackLevel);
return logbackLogger;
}

@Bean
CommandLineRunner autoConfigureDistroCommandLine(SelfDiagnosticsLevel selfDiagnosticsLevel) {
return args -> {
ILoggerFactory loggerFactorySpi = LoggerFactory.getILoggerFactory();
if (!(loggerFactorySpi instanceof LoggerContext)) {
return;
}

LoggerContext loggerContext = (LoggerContext) loggerFactorySpi;

Level selfDiagLogbackLevel = Level.toLevel(selfDiagnosticsLevel.name());

ch.qos.logback.classic.Logger azureMonitorOTelLogger = loggerContext.getLogger("com.azure.monitor.opentelemetry");
azureMonitorOTelLogger.setLevel(selfDiagLogbackLevel);
};
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation;
package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation;
package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

import com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.SelfDiagnosticsLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -21,12 +20,16 @@
@ConditionalOnProperty(name = "otel.sdk.disabled", havingValue = "false", matchIfMissing = true)
@Import({DefaultLogConfig.class, LogbackSelfDiagConfig.class})
public class SelfDiagAutoConfig {

private static final Logger LOG = LoggerFactory.getLogger(SelfDiagAutoConfig.class);

static final String SELF_DIAGNOSTICS_LEVEL_ENV_VAR = "APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL";

// Bean to remove
@Bean
SelfDiagnosticsLevel selfDiagnosticsLevel() {
String selfDiagLevelEnvVar = System.getenv(SELF_DIAGNOSTICS_LEVEL_ENV_VAR);

if (selfDiagLevelEnvVar == null) {
return SelfDiagnosticsLevel.INFO;
}
Expand All @@ -48,5 +51,4 @@ OtelSelfDiag otelSelfDiag(ApplicationContext applicationContext, Logger selfDiag
ExecutionEnvSelfDiag executionEnvSelfDiag(Logger selfDiagnosticsLogger) {
return new ExecutionEnvSelfDiag(selfDiagnosticsLogger);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation;
package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

// Class used for logging
final class SelfDiagnostics {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics;

enum SelfDiagnosticsLevel {

ERROR,
WARN,
INFO,
DEBUG,
TRACE,
OFF
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
com.azure.spring.cloud.autoconfigure.monitor.implementation.AzureSpringMonitorAutoConfiguration
com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation.SelfDiagAutoConfig
com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics.SelfDiagAutoConfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
package com.azure.spring.cloud.autoconfigure.monitor.implementation;

import com.azure.spring.cloud.autoconfigure.monitor.selfdiagnostics.implementation.SelfDiagAutoConfig;
import com.azure.spring.cloud.autoconfigure.monitor.implementation.selfdiagnostics.SelfDiagAutoConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand Down

0 comments on commit ecbfe54

Please sign in to comment.