Skip to content

Commit

Permalink
Better populate exception type name and message from span events (#41397
Browse files Browse the repository at this point in the history
)
  • Loading branch information
trask authored Aug 14, 2024
1 parent fb5b8bc commit 050be09
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,7 @@ private TelemetryItem createExceptionTelemetryItem(LogRecordData log, String sta
Attributes attributes = log.getAttributes();
MAPPINGS.map(attributes, telemetryBuilder);

List<ExceptionDetailBuilder> builders = Exceptions.minimalParse(stack);
ExceptionDetailBuilder exceptionDetailBuilder = builders.get(0);
String type = log.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE);
if (type != null && !type.isEmpty()) {
exceptionDetailBuilder.setTypeName(type);
}
String message = log.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE);
if (message != null && !message.isEmpty()) {
exceptionDetailBuilder.setMessage(message);
}
telemetryBuilder.setExceptions(builders);
SpanDataMapper.setExceptions(stack, log.getAttributes(), telemetryBuilder);
telemetryBuilder.setSeverityLevel(toSeverityLevel(log.getSeverity()));

// set exception-specific properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package com.azure.monitor.opentelemetry.exporter.implementation;

import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.ExceptionDetailBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.ExceptionTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.Exceptions;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.MessageTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.RemoteDependencyTelemetryBuilder;
import com.azure.monitor.opentelemetry.exporter.implementation.builders.RequestTelemetryBuilder;
Expand Down Expand Up @@ -36,6 +36,7 @@

import static com.azure.monitor.opentelemetry.exporter.implementation.MappingsBuilder.MappingType.SPAN;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

Expand Down Expand Up @@ -820,11 +821,25 @@ private TelemetryItem createExceptionTelemetryItem(String errorStack, SpanData s
MAPPINGS.map(span.getAttributes(), telemetryBuilder);

// set exception-specific properties
telemetryBuilder.setExceptions(Exceptions.minimalParse(errorStack));
setExceptions(errorStack, span.getAttributes(), telemetryBuilder);

return telemetryBuilder.build();
}

static void setExceptions(String stack, Attributes attributes, ExceptionTelemetryBuilder telemetryBuilder) {
ExceptionDetailBuilder builder = new ExceptionDetailBuilder();
String type = attributes.get(SemanticAttributes.EXCEPTION_TYPE);
if (type != null && !type.isEmpty()) {
builder.setTypeName(type);
}
String message = attributes.get(SemanticAttributes.EXCEPTION_MESSAGE);
if (message != null && !message.isEmpty()) {
builder.setMessage(message);
}
builder.setStack(stack);
telemetryBuilder.setExceptions(singletonList(builder));
}

public static <T> T getStableOrOldAttribute(Attributes attributes, AttributeKey<T> stable, AttributeKey<T> old) {
T value = attributes.get(stable);
if (value != null) {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 050be09

Please sign in to comment.