Skip to content

Commit

Permalink
retrrieve as env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshi0301 committed Jan 8, 2025
1 parent acee94d commit 93c7a1d
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 93c7a1d

Please sign in to comment.