-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure tracing Add @observed for more detailed observation Add loki4j for log indexing Add OpenTelemetry resource attributes
- Loading branch information
amvanbaren
committed
Feb 23, 2024
1 parent
0ce7b7b
commit 4f534d4
Showing
14 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
server/src/main/java/org/eclipse/openvsx/metrics/MetricsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** ****************************************************************************** | ||
* Copyright (c) 2024 Precies. Software Ltd and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* ****************************************************************************** */ | ||
package org.eclipse.openvsx.metrics; | ||
|
||
import io.micrometer.common.KeyValue; | ||
import io.micrometer.observation.ObservationFilter; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import io.micrometer.observation.aop.ObservedAspect; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Configuration | ||
@Profile("!test") | ||
public class MetricsConfiguration { | ||
@Bean | ||
public ObservedAspect observedAspect(ObservationRegistry observationRegistry) { | ||
return new ObservedAspect(observationRegistry, new RegistryObservationConvention()); | ||
} | ||
|
||
@Bean | ||
public ObservationFilter observationFilter( | ||
@Value("${management.metrics.tags.application:app}") String service, | ||
@Value("${management.metrics.tags.environment:development}") String environment, | ||
@Value("${management.metrics.tags.instance:local}") String instance | ||
) { | ||
return context -> context | ||
.addLowCardinalityKeyValue(KeyValue.of("service.name", service)) | ||
.addLowCardinalityKeyValue(KeyValue.of("deployment.environment", environment)) | ||
.addLowCardinalityKeyValue(KeyValue.of("service.instance.id", instance)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
server/src/main/java/org/eclipse/openvsx/metrics/RegistryObservationConvention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** ****************************************************************************** | ||
* Copyright (c) 2024 Precies. Software Ltd and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* ****************************************************************************** */ | ||
package org.eclipse.openvsx.metrics; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.micrometer.common.KeyValue; | ||
import io.micrometer.common.KeyValues; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationConvention; | ||
import io.micrometer.observation.aop.ObservedAspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
|
||
public class RegistryObservationConvention implements ObservationConvention<ObservedAspect.ObservedAspectContext> { | ||
|
||
private ObjectMapper mapper; | ||
|
||
public RegistryObservationConvention() { | ||
this.mapper = new ObjectMapper(); | ||
} | ||
|
||
@Override | ||
public KeyValues getHighCardinalityKeyValues(ObservedAspect.ObservedAspectContext context) { | ||
var joinPoint = context.getProceedingJoinPoint(); | ||
var args = joinPoint.getArgs(); | ||
var methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
var parameterNames = methodSignature.getParameterNames(); | ||
var argKeyValues = new KeyValue[args.length]; | ||
for(var i = 0; i < args.length; i++) { | ||
var key = "args." + parameterNames[i]; | ||
var value = convertObjectToString(args[i]); | ||
argKeyValues[i] = KeyValue.of(key, value); | ||
} | ||
|
||
return ObservationConvention.super.getHighCardinalityKeyValues(context).and(argKeyValues); | ||
} | ||
|
||
private String convertObjectToString(Object arg) { | ||
if(arg instanceof String) { | ||
return (String) arg; | ||
} else if(arg instanceof Number || arg instanceof Boolean) { | ||
return String.valueOf(arg); | ||
} else { | ||
try { | ||
return mapper.writeValueAsString(arg); | ||
} catch (JsonProcessingException e) { | ||
return ""; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supportsContext(Observation.Context context) { | ||
return context instanceof ObservedAspect.ObservedAspectContext; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "org.eclipse.openvsx.observed"; | ||
} | ||
|
||
@Override | ||
public String getContextualName(ObservedAspect.ObservedAspectContext context) { | ||
var methodSignature = (MethodSignature) context.getProceedingJoinPoint().getSignature(); | ||
var method = methodSignature.getMethod(); | ||
return method.getDeclaringClass().getSimpleName() + "#" + method.getName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters