Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply exception type and message #3148

Merged
merged 12 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ public CompletableResultCode export(Collection<LogRecordData> logs) {
itemCount = Math.round(100.0 / samplingPercentage);
}

TelemetryItem telemetryItem = mapper.map(log, stack, itemCount);
heyams marked this conversation as resolved.
Show resolved Hide resolved
String type =
log.getAttributes()
.get(
com.azure.monitor.opentelemetry.exporter.implementation.SemanticAttributes
.EXCEPTION_TYPE);
String message =
log.getAttributes()
.get(
com.azure.monitor.opentelemetry.exporter.implementation.SemanticAttributes
.EXCEPTION_MESSAGE);
TelemetryItem telemetryItem = mapper.map(log, stack, type, message, itemCount);
heyams marked this conversation as resolved.
Show resolved Hide resolved
telemetryItemConsumer.accept(telemetryItem);

exportingLogLogger.recordSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public CompletableResultCode export(Collection<LogRecordData> logs) {
for (LogRecordData log : logs) {
LOGGER.verbose("exporting log: {}", log);
try {
String stack = log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE);
telemetryItems.add(mapper.map(log, stack, null));
String exceptionStacktace =
log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE);
String exceptionType = log.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE);
String exceptionMessage = log.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE);
telemetryItems.add(
mapper.map(log, exceptionStacktace, exceptionType, exceptionMessage, null));
OPERATION_LOGGER.recordSuccess();
} catch (Throwable t) {
OPERATION_LOGGER.recordFailure(t.getMessage(), t, EXPORTER_MAPPING_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.azure.core.util.logging.ClientLogger;
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;
Expand All @@ -21,6 +22,7 @@
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import reactor.util.annotation.Nullable;
Expand Down Expand Up @@ -100,11 +102,16 @@ public LogDataMapper(
this.telemetryInitializer = telemetryInitializer;
}

public TelemetryItem map(LogRecordData log, @Nullable String stack, @Nullable Long itemCount) {
public TelemetryItem map(
LogRecordData log,
@Nullable String stack,
@Nullable String type,
@Nullable String message,
@Nullable Long itemCount) {
if (stack == null) {
return createMessageTelemetryItem(log, itemCount);
} else {
return createExceptionTelemetryItem(log, itemCount, stack);
return createExceptionTelemetryItem(log, itemCount, stack, type, message);
}
}
heyams marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -138,7 +145,7 @@ private TelemetryItem createMessageTelemetryItem(LogRecordData log, @Nullable Lo
}

private TelemetryItem createExceptionTelemetryItem(
LogRecordData log, @Nullable Long itemCount, String stack) {
LogRecordData log, @Nullable Long itemCount, String stack, String type, String message) {
ExceptionTelemetryBuilder telemetryBuilder = ExceptionTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, log.getResource());

Expand All @@ -151,7 +158,14 @@ private TelemetryItem createExceptionTelemetryItem(
Attributes attributes = log.getAttributes();
MAPPINGS.map(attributes, telemetryBuilder);

telemetryBuilder.setExceptions(Exceptions.minimalParse(stack));
ExceptionDetailBuilder exceptionDetailBuilder = Exceptions.minimalParse(stack).get(0);
heyams marked this conversation as resolved.
Show resolved Hide resolved
if (type != null && !type.isEmpty()) {
exceptionDetailBuilder.setTypeName(type);
}
if (message != null && !message.isEmpty()) {
exceptionDetailBuilder.setMessage(message);
}
telemetryBuilder.setExceptions(Collections.singletonList(exceptionDetailBuilder));
heyams marked this conversation as resolved.
Show resolved Hide resolved
telemetryBuilder.setSeverityLevel(toSeverityLevel(log.getSeverity()));

// set exception-specific properties
Expand Down