Skip to content
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2022 VMware, Inc.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.otel;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

import io.micrometer.common.KeyValue;
import io.micrometer.convention.otel.http.OpenTelemetryHttpClientConventions;
import io.micrometer.convention.otel.http.OpenTelemetryHttpLowCardinalityKeyNames;
import io.micrometer.convention.otel.http.OpenTelemetryHttpServerConvention;
import io.micrometer.conventions.common.AttributeType;
import io.micrometer.observation.Observation;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.observation.transport.http.context.HttpContext;
import io.micrometer.observation.transport.http.tags.HttpKeyValuesConvention;

/**
* Conventions for HTTP key values implemented with OpenTelemetry.
*
* @author Marcin Grzejszczak
* @since 1.10.0
*/
public final class OpenTelemetryConventions {

/**
* Provides all HTTP related conventions.
* @return collection of HTTP conventions
*/
public static Collection<Observation.ObservationConvention<?>> http() {
return Arrays.asList(new OpenTelemetryHttpClientConventions(), new OpenTelemetryHttpServerConvention());
}

/**
* Provides all OTel conventions.
* @return all OTel conventions
*/
public static Collection<Observation.ObservationConvention<?>> all() {
return http();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import io.micrometer.observation.Observation;
import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.observation.transport.http.HttpClientResponse;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.context.HttpClientContext;
import io.micrometer.observation.transport.http.tags.HttpClientKeyValuesConvention;

/**
Expand All @@ -26,12 +31,26 @@
* @since 1.10.0
*/
// TODO: What to do if request is not set? UNKNOWN?
public class OpenTelemetryHttpClientKeyValuesConvention extends OpenTelemetryHttpKeyValuesConvention
public class OpenTelemetryHttpClientConventions extends OpenTelemetryHttpConvention<HttpClientRequest, HttpClientResponse, HttpClientContext>
implements HttpClientKeyValuesConvention {

@Override
public KeyValue peerName(HttpRequest request) {
return OpenTelemetryHttpClientLowCardinalityKeyNames.PEER_NAME.of("UNKNOWN");
}

@Override
public String getName() {
return "http.client.duration";
}

@Override
public boolean supportsContext(Observation.Context context) {
return context instanceof HttpClientContext;
}

@Override
public KeyValues getLowCardinalityKeyValues(HttpClientContext context) {
return all(context.getRequest(), context.getResponse());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import io.micrometer.common.docs.KeyName;
import io.micrometer.conventions.semantic.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import java.util.function.Predicate;
import java.util.stream.Stream;

import io.micrometer.common.KeyValue;
import io.micrometer.conventions.common.AttributeType;
import io.micrometer.observation.Observation;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.observation.transport.http.context.HttpContext;
import io.micrometer.observation.transport.http.tags.HttpKeyValuesConvention;

/**
Expand All @@ -31,7 +33,7 @@
* @since 1.10.0
*/
// TODO: What to do if request is not set? UNKNOWN?
abstract class OpenTelemetryHttpKeyValuesConvention implements HttpKeyValuesConvention {
abstract class OpenTelemetryHttpConvention<REQ extends HttpRequest, RES extends HttpResponse, CONTEXT extends HttpContext<REQ, RES>> implements HttpKeyValuesConvention, Observation.ObservationConvention<CONTEXT> {

// TODO: This is just an example
private static final Predicate<Object> METHOD_PREDICATE = s -> isTypeCorrect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import io.micrometer.common.docs.KeyName;
import io.micrometer.conventions.semantic.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import io.micrometer.common.KeyValue;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.Observation;
import io.micrometer.observation.transport.http.*;
import io.micrometer.observation.transport.http.context.HttpServerContext;
import io.micrometer.observation.transport.http.tags.HttpServerKeyValuesConvention;

/**
Expand All @@ -26,7 +28,7 @@
* @since 1.10.0
*/
// TODO: What to do if request is not set? UNKNOWN?
public class OpenTelemetryHttpServerKeyValuesConvention extends OpenTelemetryHttpKeyValuesConvention
public class OpenTelemetryHttpServerConvention extends OpenTelemetryHttpConvention<HttpServerRequest, HttpServerResponse, HttpServerContext>
implements HttpServerKeyValuesConvention {

@Override
Expand All @@ -49,4 +51,13 @@ public KeyValue clientIp(HttpRequest request) {
return OpenTelemetryHttpServerLowCardinalityKeyNames.CLIENT_IP.of("UNKNOWN");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there something missing? Extracing the client IP from the request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, everything is missing - I've done only the method key value as an example :)

}

@Override
public String getName() {
return "http.server.duration";
}

@Override
public boolean supportsContext(Observation.Context context) {
return context instanceof HttpServerContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.convention.http.tag;
package io.micrometer.convention.otel.http;

import io.micrometer.common.docs.KeyName;
import io.micrometer.conventions.semantic.SemanticAttributes;
Expand Down
Loading