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

Support ingestion sampling #39103

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -110,7 +110,7 @@ public TelemetryItem map(LogRecordData log, @Nullable String stack, @Nullable Lo
}
}

private TelemetryItem createMessageTelemetryItem(LogRecordData log, long itemCount) {
private TelemetryItem createMessageTelemetryItem(LogRecordData log, @Nullable Long itemCount) {
MessageTelemetryBuilder telemetryBuilder = MessageTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, log.getResource());

Expand Down Expand Up @@ -140,7 +140,7 @@ private TelemetryItem createMessageTelemetryItem(LogRecordData log, long itemCou
}

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

Expand Down Expand Up @@ -212,13 +212,15 @@ private static long getTimestampEpochNanosWithFallback(LogRecordData log) {
}


private static void setItemCount(AbstractTelemetryBuilder telemetryBuilder, long itemCount) {
telemetryBuilder.setSampleRate(100.0f / itemCount);
private static void setItemCount(AbstractTelemetryBuilder telemetryBuilder, @Nullable Long itemCount) {
if (itemCount != null) {
telemetryBuilder.setSampleRate(100.0f / itemCount);
}
}

private static long getItemCount(LogRecordData log) {
Long itemCount = log.getAttributes().get(AiSemanticAttributes.ITEM_COUNT);
return itemCount == null ? 1 : itemCount;
@Nullable
private static Long getItemCount(LogRecordData log) {
return log.getAttributes().get(AiSemanticAttributes.ITEM_COUNT);
}

private static void setFunctionExtraTraceAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public SpanDataMapper(
}

public TelemetryItem map(SpanData span) {
long itemCount = getItemCount(span);
Long itemCount = getItemCount(span);
return map(span, itemCount);
}

public void map(SpanData span, Consumer<TelemetryItem> consumer) {
long itemCount = getItemCount(span);
Long itemCount = getItemCount(span);
TelemetryItem telemetryItem = map(span, itemCount);
consumer.accept(telemetryItem);
exportEvents(
Expand All @@ -140,7 +140,7 @@ public void map(SpanData span, Consumer<TelemetryItem> consumer) {
}

// TODO looks like this method can be private
public TelemetryItem map(SpanData span, long itemCount) {
public TelemetryItem map(SpanData span, @Nullable Long itemCount) {
if (RequestChecker.isRequest(span)) {
return exportRequest(span, itemCount);
} else {
Expand All @@ -154,7 +154,7 @@ private static boolean checkIsPreAggregatedStandardMetric(SpanData span) {
return isPreAggregatedStandardMetric != null && isPreAggregatedStandardMetric;
}

private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, long itemCount) {
private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, @Nullable Long itemCount) {
RemoteDependencyTelemetryBuilder telemetryBuilder = RemoteDependencyTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, span.getResource());

Expand Down Expand Up @@ -502,7 +502,7 @@ private static int getDefaultPortForDbSystem(String dbSystem) {
}
}

private TelemetryItem exportRequest(SpanData span, long itemCount) {
private TelemetryItem exportRequest(SpanData span, @Nullable Long itemCount) {
RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, span.getResource());

Expand Down Expand Up @@ -748,7 +748,7 @@ private static String nullAwareConcat(
private void exportEvents(
SpanData span,
@Nullable String operationName,
long itemCount,
@Nullable Long itemCount,
Consumer<TelemetryItem> consumer) {
for (EventData event : span.getEvents()) {
String instrumentationScopeName = span.getInstrumentationScopeInfo().getName();
Expand Down Expand Up @@ -799,7 +799,7 @@ private void exportEvents(
}

private TelemetryItem createExceptionTelemetryItem(
String errorStack, SpanData span, @Nullable String operationName, long itemCount) {
String errorStack, SpanData span, @Nullable String operationName, @Nullable Long itemCount) {

ExceptionTelemetryBuilder telemetryBuilder = ExceptionTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, span.getResource());
Expand Down Expand Up @@ -836,13 +836,15 @@ private static void setTime(AbstractTelemetryBuilder telemetryBuilder, long epoc
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(epochNanos));
}

private static void setItemCount(AbstractTelemetryBuilder telemetryBuilder, long itemCount) {
telemetryBuilder.setSampleRate(100.0f / itemCount);
private static void setItemCount(AbstractTelemetryBuilder telemetryBuilder, @Nullable Long itemCount) {
if (itemCount != null) {
telemetryBuilder.setSampleRate(100.0f / itemCount);
}
}

private static long getItemCount(SpanData span) {
Long itemCount = span.getAttributes().get(AiSemanticAttributes.ITEM_COUNT);
return itemCount == null ? 1 : itemCount;
@Nullable
private static Long getItemCount(SpanData span) {
return span.getAttributes().get(AiSemanticAttributes.ITEM_COUNT);
}

private static void addLinks(AbstractTelemetryBuilder telemetryBuilder, List<LinkData> links) {
Expand Down
Loading