Skip to content

Commit

Permalink
Polish "Tck with observations" (#3446)
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Oct 3, 2022
1 parent 1610a18 commit 62ad361
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static Tag status(HttpServletResponse response) {
}

/**
* Creates a {@code exception} tag based on the {@link Class#getSimpleName() simple
* Creates an {@code exception} tag based on the {@link Class#getSimpleName() simple
* name} of the class of the given {@code exception}.
* @param exception the exception, may be {@code null}
* @return the exception tag derived from the exception
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 VMware, Inc.
* Copyright 2022 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 VMware, Inc.
* Copyright 2022 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,7 +100,7 @@ static KeyValue uri(RequestEvent event) {
}

/**
* Creates a {@code exception} KeyValue based on the {@link Class#getSimpleName()
* Creates an {@code exception} KeyValue based on the {@link Class#getSimpleName()
* simple name} of the class of the given {@code exception}.
* @param event the request event
* @return the exception KeyValue derived from the exception
Expand All @@ -121,8 +121,8 @@ static KeyValue exception(RequestEvent event) {
exception = exception.getCause();
}
String simpleName = exception.getClass().getSimpleName();
return KeyValue.of("exception",
StringUtils.isNotEmpty(simpleName) ? simpleName : exception.getClass().getName());
return JerseyObservationDocumentation.JerseyLegacyLowCardinalityTags.EXCEPTION
.withValue(StringUtils.isNotEmpty(simpleName) ? simpleName : exception.getClass().getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.micrometer.core.instrument.binder.jersey.server;

import io.micrometer.core.instrument.Tag;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationConvention;

/**
* Provides {@link Tag Tags} for Jersey request metrics.
* Provides names and {@link io.micrometer.common.KeyValues} for Jersey request
* observations.
*
* @author Marcin Grzejszczak
* @since 1.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static String getMatchingPattern(RequestEvent event) {
}

/**
* Creates a {@code exception} tag based on the {@link Class#getSimpleName() simple
* Creates an {@code exception} tag based on the {@link Class#getSimpleName() simple
* name} of the class of the given {@code exception}.
* @param event the request event
* @return the exception tag derived from the exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ public class ObservationRequestEventListener implements RequestEventListener {

private final ObservationRegistry registry;

private final JerseyObservationConvention jerseyObservationConvention;
private final JerseyObservationConvention customConvention;

private final String metricName;

private final JerseyObservationConvention defaultConvention;

public ObservationRequestEventListener(ObservationRegistry registry, String metricName) {
this(registry, metricName, null);
}

public ObservationRequestEventListener(ObservationRegistry registry, String metricName,
JerseyObservationConvention jerseyObservationConvention) {
JerseyObservationConvention customConvention) {
this.registry = requireNonNull(registry);
this.metricName = requireNonNull(metricName);
this.jerseyObservationConvention = jerseyObservationConvention;
this.customConvention = customConvention;
this.defaultConvention = new DefaultJerseyObservationConvention(this.metricName);
}

@Override
Expand All @@ -67,8 +70,8 @@ public void onEvent(RequestEvent event) {
}
case REQUEST_MATCHED:
JerseyContext jerseyContext = new JerseyContext(event);
Observation observation = JerseyObservationDocumentation.DEFAULT.start(this.jerseyObservationConvention,
new DefaultJerseyObservationConvention(this.metricName), () -> jerseyContext, this.registry);
Observation observation = JerseyObservationDocumentation.DEFAULT.start(this.customConvention,
this.defaultConvention, () -> jerseyContext, this.registry);
Observation.Scope scope = observation.openScope();
observations.put(event.getContainerRequest(), new ObservationScopeAndContext(scope, jerseyContext));
break;
Expand All @@ -81,7 +84,6 @@ public void onEvent(RequestEvent event) {
break;
case FINISHED:
ObservationScopeAndContext finishedObservation = observations.remove(containerRequest);

if (finishedObservation != null) {
finishedObservation.jerseyContext.setRequestEvent(event);
Observation.Scope observationScope = finishedObservation.observationScope;
Expand All @@ -90,6 +92,7 @@ public void onEvent(RequestEvent event) {
}
break;
default:
break;
}
}

Expand Down

0 comments on commit 62ad361

Please sign in to comment.