Skip to content
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
24 changes: 24 additions & 0 deletions micrometer-conventions-experimental/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
description 'Module containing common Micrometer Conventions code'

dependencies {
api 'io.micrometer:micrometer-commons'
api 'io.micrometer:micrometer-observation'

// log monitoring
testImplementation 'com.squareup.okhttp3:okhttp'
testImplementation 'org.apache.logging.log4j:log4j-core'

testImplementation 'io.micrometer:micrometer-core'
testImplementation 'io.micrometer:micrometer-observation-test'

// JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter'

testImplementation 'org.mockito:mockito-inline'

testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'

testImplementation 'ru.lanwen.wiremock:wiremock-junit5'
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;

/**
* Conventions for HTTP client key values.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
// TODO: This could go to a separate, "core" module?
public interface HttpClientKeyValuesConvention<REQ, RES> extends HttpKeyValuesConvention<REQ, RES> {

/**
* Remote hostname or similar, see note below.
*
* Examples: example.com
*
* SHOULD NOT be set if capturing it would require an extra DNS lookup.
* @param request HTTP request
* @return key value
*/
KeyValue peerName(REQ request);

@Override
default KeyValues all(REQ request, RES response) {
return HttpKeyValuesConvention.super.all(request, response).and(peerName(request));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* 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;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import io.micrometer.observation.Observation;

/**
* Conventions for HTTP key values.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
// TODO: This could go to a separate, "core" module?
public interface HttpKeyValuesConvention<REQ, RES> extends Observation.KeyValuesConvention {

/**
* HTTP request method.
*
* Examples: GET; POST; HEAD
* @param request HTTP request
* @return key value
*/
KeyValue method(REQ request);

/**
* Full HTTP request URL in the form scheme://host[:port]/path?query[#fragment].
* Usually the fragment is not transmitted over HTTP, but if it is known, it should be
* included nevertheless.
*
* Examples: https://www.foo.bar/search?q=OpenTelemetry#SemConv
* @param request HTTP request
* @return key value
*/
KeyValue url(REQ request);

/**
* The full request target as passed in a HTTP request line or equivalent.
*
* Examples: /path/12314/?q=ddds#123
* @param request HTTP request
* @return key value
*/
KeyValue target(REQ request);

/**
* The value of the HTTP host header. An empty Host header should also be reported,
* see note.
*
* Examples: www.example.org
* @param request HTTP request
* @return key value
*/
KeyValue host(REQ request);

/**
* The URI scheme identifying the used protocol.
*
* Examples: http; https
* @param request HTTP request
* @return key value
*/
KeyValue scheme(REQ request);

/**
* HTTP response status code.
*
* Examples: 200
* @param response HTTP response
* @return key value
*/
KeyValue statusCode(RES response);

/**
* Kind of HTTP protocol used.
*
* Examples: 1.0
* @param request HTTP request
* @return key value
*/
KeyValue flavor(REQ request);

/**
* Value of the HTTP User-Agent header sent by the client.
*
* Examples: CERN-LineMode/2.15 libwww/2.17b3
* @param request HTTP request
* @return key value
*/
KeyValue userAgent(REQ request);

/**
* The size of the request payload body in bytes. This is the number of bytes
* transferred excluding headers and is often, but not always, present as the
* Content-Length header. For requests using transport encoding, this should be the
* compressed size.
*
* Examples: 3495
* @param request HTTP request
* @return key value
*/
KeyValue requestContentLength(REQ request);

/**
* The size of the response payload body in bytes. This is the number of bytes
* transferred excluding headers and is often, but not always, present as the
* Content-Length header. For requests using transport encoding, this should be the
* compressed size.
*
* Examples: 3495
* @param response HTTP response
* @return key value
*/
KeyValue responseContentLength(RES response);

/**
* Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6)
*
* Examples: 127.0.0.1
* @param request HTTP request
* @return key value
*/
KeyValue ip(REQ request);

/**
* Remote port number.
*
* Examples: 80; 8080; 443
* @param request HTTP request
* @return key value
*/
KeyValue port(REQ request);

/**
* Sets all key values.
* @param request HTTP request
* @param response HTTP response
* @return all key values
*/
default KeyValues all(REQ request, RES response) {
return KeyValues.of(method(request), url(request), target(request), host(request), scheme(request),
statusCode(response), flavor(request), userAgent(request), requestContentLength(request),
responseContentLength(response), ip(request), port(request));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;

/**
* Conventions for HTTP server key values.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
// TODO: This could go to a separate, "core" module?
public interface HttpServerKeyValuesConvention<REQ, RES> extends HttpKeyValuesConvention<REQ, RES> {

/**
* The primary server name of the matched virtual host. This should be obtained via
* configuration. If no such configuration can be obtained, this attribute MUST NOT be
* set ( net.host.name should be used instead).
* <p>
* Examples: example.com
* @param request HTTP request
* @return key value
*/
KeyValue serverName(REQ request);

// TODO: In OTel - we will set not templated version

/**
* The matched route.
* <p>
* Examples: /users/5
* @param request HTTP request
* @return key value
*/
KeyValue route(REQ request);

// TODO: Not in OTEL

/**
* The matched route (path template).
* <p>
* Examples: /users/:userID?
* @param request HTTP request
* @return key value
*/
KeyValue templatedRoute(REQ request);

/**
* The IP address of the original client behind all proxies, if known (e.g. from
* X-Forwarded-For).
* <p>
* Examples: 83.164.160.102
* @param request HTTP request
* @return key value
*/
KeyValue clientIp(REQ request);

@Override
default KeyValues all(REQ request, RES response) {
return HttpKeyValuesConvention.super.all(request, response).and(serverName(request), route(request),
templatedRoute(request), clientIp(request));
}

}
1 change: 1 addition & 0 deletions micrometer-otel-conventions-experimental/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
description 'Module containing implementations of Micrometer Observation naming conventions'

dependencies {
api project(":micrometer-conventions-experimental")
api project(":micrometer-otel-conventions-experimental-semver")
api 'io.micrometer:micrometer-observation'

Expand Down

This file was deleted.

Loading