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

Otel Configuration on Testcontainers #1126

Closed
wants to merge 18 commits into from
Closed
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
19 changes: 13 additions & 6 deletions dapr-spring/dapr-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.dapr.spring.data.observation;

import io.micrometer.observation.transport.SenderContext;

import java.util.HashMap;
import java.util.Map;


/**
* {@link SenderContext} for Dapr KeyValue context.
*
*/
public final class DaprKeyValueContext extends SenderContext<DaprKeyValueContext.KeyValueHolder> {

private final String beanName;

private final String keyValueStore;


private DaprKeyValueContext(KeyValueHolder keyValueHolder, String keyValueStore, String beanName) {
super((carrier, key, value) -> keyValueHolder.property(key, value));
setCarrier(keyValueHolder);
this.beanName = beanName;
this.keyValueStore = keyValueStore;
}

/**
* Create a new context.
* @param kvStore KVStore to be used
* @param beanName name of the bean used usually (typically a {@code DaprMessagingTemplate})
* @return DaprMessageSenderContext
*/
public static DaprKeyValueContext newContext(String kvStore, String beanName) {
KeyValueHolder keyValueHolder = new KeyValueHolder();
return new DaprKeyValueContext(keyValueHolder, kvStore, beanName);
}

public Map<String, String> properties() {
return getCarrier().properties();
}


/**
* The name of the bean interacting with the KeyValue Store (typically a {@code DaprKeyValueTemplate}).
* @return the name of the bean interacting with the KeyValue store
*/
public String getBeanName() {
return this.beanName;
}

/**
* The KeyValue store used for storing/retriving data.
* @return the key value store used
*/
public String getKeyValueStore() {
return this.keyValueStore;
}


/**
* Acts as a carrier for a Dapr KeyValue and records the propagated properties for
* later access by the Dapr.
*/
public static final class KeyValueHolder {

private final Map<String, String> properties = new HashMap<>();

private KeyValueHolder() {
}

public void property(String key, String value) {
this.properties.put(key, value);
}

public Map<String, String> properties() {
return this.properties;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.dapr.spring.data.observation;

import io.micrometer.common.docs.KeyName;
import io.micrometer.observation.Observation;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationConvention;
import io.micrometer.observation.docs.ObservationDocumentation;

/**
* An {@link Observation} for {@link io.dapr.spring.data.DaprKeyValueTemplate}.
*
*/
public enum DaprKeyValueTemplateObservation implements ObservationDocumentation {

/**
* Observation created when a Dapr template interacts with a KVStore.
*/
TEMPLATE_OBSERVATION {

@Override
public Class<? extends ObservationConvention<? extends Context>> getDefaultConvention() {
return DefaultDaprKeyValueTemplateObservationConvention.class;
}

@Override
public String getPrefix() {
return "spring.dapr.data.template";
}

@Override
public KeyName[] getLowCardinalityKeyNames() {
return TemplateLowCardinalityTags.values();
}

};

/**
* Low cardinality tags.
*/
public enum TemplateLowCardinalityTags implements KeyName {

/**
* Bean name of the template that interacts with the kv store.
*/
BEAN_NAME {

@Override
public String asString() {
return "spring.dapr.data.template.name";
}

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.dapr.spring.data.observation;


import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationConvention;

/**
* {@link ObservationConvention} for Dapr KV template .
*
*/
public interface DaprKeyValueTemplateObservationConvention extends ObservationConvention<DaprKeyValueContext> {

@Override
default boolean supportsContext(Context context) {
return context instanceof DaprKeyValueContext;
}

@Override
default String getName() {
return "spring.dapr.data.template";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.dapr.spring.data.observation;

import io.micrometer.common.KeyValues;

/**
* Default {@link DefaultDaprKeyValueTemplateObservationConvention} for Dapr template key values.
*
*/
public class DefaultDaprKeyValueTemplateObservationConvention implements DaprKeyValueTemplateObservationConvention {

/**
* A singleton instance of the convention.
*/
public static final DefaultDaprKeyValueTemplateObservationConvention INSTANCE =
new DefaultDaprKeyValueTemplateObservationConvention();

@Override
public KeyValues getLowCardinalityKeyValues(DaprKeyValueContext context) {
return KeyValues.of(DaprKeyValueTemplateObservation.TemplateLowCardinalityTags.BEAN_NAME.asString(),
context.getBeanName());
}

// Remove once addressed:
// https://github.com/micrometer-metrics/micrometer-docs-generator/issues/30
@Override
public String getName() {
return "spring.dapr.data.template";
}

@Override
public String getContextualName(DaprKeyValueContext context) {
return context.getKeyValueStore() + " store";
}

}
10 changes: 10 additions & 0 deletions dapr-spring/dapr-spring-messaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
<artifactId>dapr-spring-messaging</artifactId>
<name>dapr-spring-messaging</name>
<description>Dapr Spring Messaging</description>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
</dependency>
</dependencies>
<packaging>jar</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import reactor.core.publisher.Mono;

/**
* Create a new DaprMessagingOperations.
* @param <T> payload type
*/
public interface DaprMessagingOperations<T> {

/**
Expand Down
Loading