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

Replace Temporary Views with Metrics View API #7474

Closed
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
2 changes: 1 addition & 1 deletion instrumentation-api-semconv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies {
annotationProcessor("com.google.auto.value:auto-value")

testImplementation(project(":testing-common"))
testImplementation("io.opentelemetry:opentelemetry-sdk-metrics")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-incubator")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

package io.opentelemetry.instrumentation.api.instrumenter.http;

import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView;
import static java.util.logging.Level.FINE;

import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongHistogram;
Expand All @@ -21,7 +19,6 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* {@link OperationListener} which keeps track of <a
Expand Down Expand Up @@ -90,35 +87,20 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
context);
return;
}
Attributes durationAndSizeAttributes =
applyClientDurationAndSizeView(state.startAttributes(), endAttributes);
duration.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAndSizeAttributes, context);
Long requestLength =
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
Attributes attributes = mergeAttributes(state.startAttributes(), endAttributes);
duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_MS, attributes, context);
Long requestLength = attributes.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, attributes);
}
Long responseLength =
getAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
endAttributes,
state.startAttributes());
Long responseLength = attributes.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, attributes);
}
}

@Nullable
private static <T> T getAttribute(AttributeKey<T> key, Attributes... attributesList) {
for (Attributes attributes : attributesList) {
T value = attributes.get(key);
if (value != null) {
return value;
}
}
return null;
private static Attributes mergeAttributes(Attributes attr1, Attributes attr2) {
return Attributes.builder().putAll(attr1).putAll(attr2).build();
}

@AutoValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

package io.opentelemetry.instrumentation.api.instrumenter.http;

import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyActiveRequestsView;
import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyServerDurationAndSizeView;
import static java.util.logging.Level.FINE;

import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongHistogram;
Expand All @@ -23,7 +20,6 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* {@link OperationListener} which keeps track of <a
Expand Down Expand Up @@ -85,7 +81,7 @@ private HttpServerMetrics(Meter meter) {

@Override
public Context onStart(Context context, Attributes startAttributes, long startNanos) {
activeRequests.add(1, applyActiveRequestsView(startAttributes), context);
activeRequests.add(1, startAttributes, context);

return context.with(
HTTP_SERVER_REQUEST_METRICS_STATE,
Expand All @@ -102,36 +98,21 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
context);
return;
}
activeRequests.add(-1, applyActiveRequestsView(state.startAttributes()), context);
Attributes durationAndSizeAttributes =
applyServerDurationAndSizeView(state.startAttributes(), endAttributes);
duration.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAndSizeAttributes, context);
Long requestLength =
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
Attributes attributes = mergeAttributes(state.startAttributes(), endAttributes);
activeRequests.add(-1, attributes, context);
duration.record((endNanos - state.startTimeNanos()) / NANOS_PER_MS, attributes, context);
Long requestLength = attributes.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, attributes);
}
Long responseLength =
getAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
endAttributes,
state.startAttributes());
Long responseLength = attributes.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, attributes);
}
}

@Nullable
private static <T> T getAttribute(AttributeKey<T> key, Attributes... attributesList) {
for (Attributes attributes : attributesList) {
T value = attributes.get(key);
if (value != null) {
return value;
}
}
return null;
private static Attributes mergeAttributes(Attributes attr1, Attributes attr2) {
return Attributes.builder().putAll(attr1).putAll(attr2).build();
}

@AutoValue
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.instrumentation.api.instrumenter.rpc;

import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView;
import static java.util.logging.Level.FINE;

import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -70,10 +69,13 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
context);
return;
}
clientDurationHistogram.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS,
applyClientView(state.startAttributes(), endAttributes),
context);
Attributes attributes = mergeAttributes(state.startAttributes(), endAttributes);
double durationMs = (endNanos - state.startTimeNanos()) / NANOS_PER_MS;
clientDurationHistogram.record(durationMs, attributes, context);
}

private static Attributes mergeAttributes(Attributes attr1, Attributes attr2) {
return Attributes.builder().putAll(attr1).putAll(attr2).build();
}

@AutoValue
Expand Down
Loading