-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Micrometer observations #1828
Micrometer observations #1828
Changes from all commits
212fdf2
5e8192c
e23a805
97b23e9
9119a61
8832aff
75f5a97
6a213cf
4a9d1fb
5afb234
f02d3ca
2551952
2392312
24ae435
a2c4323
4b675d7
258c464
ba413e8
734272c
0421e72
91ec111
0784382
80f2e77
a2f21fa
f1524cb
9f7a144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2012-2022 The Feign Authors | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 feign.micrometer; | ||
|
||
import feign.Request; | ||
import feign.Response; | ||
import io.micrometer.common.KeyValues; | ||
import io.micrometer.common.lang.Nullable; | ||
|
||
/** | ||
* Default implementation of {@link FeignObservationConvention}. | ||
* | ||
* @since 1.10.0 | ||
* @see FeignObservationConvention | ||
*/ | ||
public class DefaultFeignObservationConvention implements FeignObservationConvention { | ||
|
||
/** | ||
* Singleton instance of this convention. | ||
*/ | ||
public static final DefaultFeignObservationConvention INSTANCE = | ||
new DefaultFeignObservationConvention(); | ||
|
||
// There is no need to instantiate this class multiple times, but it may be extended, | ||
// hence protected visibility. | ||
protected DefaultFeignObservationConvention() {} | ||
|
||
@Override | ||
public String getName() { | ||
return "http.client.requests"; | ||
} | ||
|
||
@Override | ||
public String getContextualName(FeignContext context) { | ||
return "HTTP " + getMethodString(context.getCarrier()); | ||
} | ||
|
||
@Override | ||
public KeyValues getLowCardinalityKeyValues(FeignContext context) { | ||
String templatedUrl = context.getCarrier().requestTemplate().methodMetadata().template().url(); | ||
return KeyValues.of( | ||
FeignObservationDocumentation.HttpClientTags.METHOD | ||
.withValue(getMethodString(context.getCarrier())), | ||
FeignObservationDocumentation.HttpClientTags.URI | ||
.withValue(templatedUrl), | ||
FeignObservationDocumentation.HttpClientTags.STATUS | ||
.withValue(getStatusValue(context.getResponse()))); | ||
} | ||
|
||
String getStatusValue(@Nullable Response response) { | ||
return response != null ? String.valueOf(response.status()) : "CLIENT_ERROR"; | ||
} | ||
|
||
String getMethodString(@Nullable Request request) { | ||
return request.httpMethod().name(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2012-2022 The Feign Authors | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 feign.micrometer; | ||
|
||
import feign.Request; | ||
import feign.Response; | ||
import io.micrometer.observation.transport.RequestReplySenderContext; | ||
import io.micrometer.observation.transport.SenderContext; | ||
|
||
/** | ||
* A {@link SenderContext} for Feign. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 1.10.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, Feign next release going to be |
||
*/ | ||
public class FeignContext extends RequestReplySenderContext<Request, Response> { | ||
|
||
public FeignContext(Request request) { | ||
super(Request::header); | ||
setCarrier(request); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2012-2022 The Feign Authors | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 feign.micrometer; | ||
|
||
import io.micrometer.core.instrument.binder.httpcomponents.DefaultApacheHttpClientObservationConvention; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationConvention; | ||
|
||
/** | ||
* {@link ObservationConvention} for Feign. | ||
* | ||
* @since 1.10.0 | ||
* @see DefaultApacheHttpClientObservationConvention | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure either, you wrote that =) |
||
*/ | ||
public interface FeignObservationConvention extends ObservationConvention<FeignContext> { | ||
|
||
@Override | ||
default boolean supportsContext(Observation.Context context) { | ||
return context instanceof FeignContext; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@since 13.0
?