Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ void observeWithHandlers() {
Observation.Event event2 = Observation.Event.of("testEvent", "event for testing",
System.currentTimeMillis());
observation.event(event2);
Observation.Event event3 = Observation.Event.of("retry", "retry", System.currentTimeMillis(),
KeyValues.of("retryCount", "2"));
observation.event(event3);

inOrder.verify(handler).onEvent(same(event), isA(Observation.Context.class));
inOrder.verify(handler).onEvent(same(event2), isA(Observation.Context.class));
inOrder.verify(handler).onEvent(same(event3), isA(Observation.Context.class));

Throwable exception = new IOException("simulated");
observation.error(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,22 @@ static Event of(String name, String contextualName) {
* @since 1.12.0
*/
static Event of(String name, String contextualName, long wallTime) {
return new SimpleEvent(name, contextualName, wallTime);
return new SimpleEvent(name, contextualName, wallTime, KeyValues.empty());
}

/**
* Creates an {@link Event}.
* @param name The name of the event (should have low cardinality).
* @param contextualName The contextual name of the event (can have high
* cardinality).
* @param wallTime Wall time when the event happened in milliseconds since the
* epoch
* @param keyValues metadata specific to the event
* @return event
* @since 1.15.0
*/
static Event of(String name, String contextualName, long wallTime, Iterable<KeyValue> keyValues) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the handlers event keyvalues can be used:

  1. Low cardinality keyvalues can be attached to metrics: right now we create a counter, we can merge the low cardinality keyvalues of the observation with the the low cardinality keyvalues of the event.
  2. All keyvalues (low+high) can be attached to the annotation of the span (in case of zipkin we can encode it to k1=v1;k2=v2 format I think).

return new SimpleEvent(name, contextualName, wallTime, keyValues);
}

/**
Expand Down Expand Up @@ -1322,6 +1337,16 @@ default String getContextualName() {
return getName();
}

/**
* Metadata about the event in the form of {@link KeyValue}. It may be empty if
* there is no metadata specific to the event.
* @return key values associated with this event
* @since 1.15.0
*/
default Iterable<KeyValue> getKeyValues() {
return KeyValues.empty();
}

/**
* Creates a new event with the given dynamic entries for the contextual name.
* @param dynamicEntriesForContextualName variables to be resolved in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.micrometer.observation;

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

/**
Expand All @@ -32,19 +34,22 @@ class SimpleEvent implements Event {

private final long wallTime;

private final Iterable<KeyValue> keyValues;

SimpleEvent(String name, String contextualName) {
this(name, contextualName, System.currentTimeMillis());
this(name, contextualName, System.currentTimeMillis(), KeyValues.empty());
}

/**
* @param name The name of the event (should have low cardinality).
* @param contextualName The contextual name of the event (can have high cardinality).
* @param wallTime Wall time in milliseconds since the epoch
*/
SimpleEvent(String name, String contextualName, long wallTime) {
SimpleEvent(String name, String contextualName, long wallTime, Iterable<KeyValue> keyValues) {
this.name = name;
this.contextualName = contextualName;
this.wallTime = wallTime;
this.keyValues = keyValues;
}

@Override
Expand All @@ -62,6 +67,11 @@ public long getWallTime() {
return this.wallTime;
}

@Override
public Iterable<KeyValue> getKeyValues() {
return this.keyValues;
}

@Override
public String toString() {
return "event.name='" + getName() + "', event.contextualName='" + getContextualName() + "', event.wallTime="
Expand Down