Skip to content

Commit

Permalink
Merge pull request #3953 from atlanhq/dev/otel3
Browse files Browse the repository at this point in the history
retrrieve as env variables
  • Loading branch information
aarshi0301 authored Jan 8, 2025
2 parents b726afa + 93c7a1d commit 02b0490
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public enum AtlasConfiguration {
* OTEL Configuration
*/
OTEL_RESOURCE_ATTRIBUTES("OTEL_RESOURCE_ATTRIBUTES", "service.name=atlas"),
OTEL_SERVICE_NAME(" OTEL_SERVICE_NAME", "atlas"),
OTEL_SERVICE_NAME("OTEL_SERVICE_NAME", "atlas"),
OTEL_EXPORTER_OTLP_ENDPOINT("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317");


Expand Down
20 changes: 16 additions & 4 deletions webapp/src/main/java/org/apache/atlas/Atlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,23 @@ private static void setApplicationHome() {

private static OpenTelemetry initializeOpenTelemetry() {

List<String> customResourceAttr =
Arrays.asList(AtlasConfiguration.OTEL_RESOURCE_ATTRIBUTES.getStringArray());
String otelResourceAttributes = System.getenv("OTEL_RESOURCE_ATTRIBUTES");

List<String> customResourceAttr = null;

if (otelResourceAttributes != null) {
// Split the environment variable by commas
String[] values = otelResourceAttributes.split(",");
customResourceAttr = Arrays.asList(values);
} else {
customResourceAttr = Arrays.asList(AtlasConfiguration.OTEL_RESOURCE_ATTRIBUTES.getStringArray());
}

String serviceName = System.getenv("OTEL_SERVICE_NAME") != null ? System.getenv("OTEL_SERVICE_NAME") : AtlasConfiguration.OTEL_SERVICE_NAME.getString();
String otelEndpoint = System.getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != null ? System.getenv("OTEL_EXPORTER_OTLP_ENDPOINT") : AtlasConfiguration.OTEL_EXPORTER_OTLP_ENDPOINT.getString();

ResourceBuilder resourceBuilder = Resource.getDefault().toBuilder()
.put(ResourceAttributes.SERVICE_NAME, AtlasConfiguration.OTEL_SERVICE_NAME.getString());
.put(ResourceAttributes.SERVICE_NAME, serviceName);

// Iterate through the ArrayList and add each attribute
for (String attribute : customResourceAttr) {
Expand All @@ -212,7 +224,7 @@ private static OpenTelemetry initializeOpenTelemetry() {
.addLogRecordProcessor(
BatchLogRecordProcessor.builder(
OtlpGrpcLogRecordExporter.builder()
.setEndpoint(AtlasConfiguration.OTEL_EXPORTER_OTLP_ENDPOINT.getString())
.setEndpoint(otelEndpoint)
.build()
)
.build()
Expand Down

0 comments on commit 02b0490

Please sign in to comment.