Skip to content

Commit 2d2104b

Browse files
committed
fixup: apply changes according to the semconv
The semconv has changed, and some attributes have been renamed. Furthermore, the body usage is deprecated and should be part of the attributes. see: open-telemetry/semantic-conventions#1990 Signed-off-by: Simon Schrottner <[email protected]>
1 parent 6c67511 commit 2d2104b

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

src/main/java/dev/openfeature/sdk/EvaluationEvent.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ public class EvaluationEvent {
1818
@Singular("attribute")
1919
private Map<String, Object> attributes;
2020

21-
@Singular("bodyElement")
22-
private Map<String, Object> body;
23-
2421
public Map<String, Object> getAttributes() {
2522
return new HashMap<>(attributes);
2623
}
27-
28-
public Map<String, Object> getBody() {
29-
return new HashMap<>(body);
30-
}
3124
}

src/main/java/dev/openfeature/sdk/Telemetry.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ private Telemetry() {}
1414
*/
1515
public static final String TELEMETRY_KEY = "feature_flag.key";
1616
public static final String TELEMETRY_ERROR_CODE = "error.type";
17-
public static final String TELEMETRY_VARIANT = "feature_flag.variant";
17+
public static final String TELEMETRY_VARIANT = "feature_flag.result.variant";
18+
public static final String TELEMETRY_VALUE = "feature_flag.result.value";
1819
public static final String TELEMETRY_CONTEXT_ID = "feature_flag.context.id";
1920
public static final String TELEMETRY_ERROR_MSG = "feature_flag.evaluation.error.message";
20-
public static final String TELEMETRY_REASON = "feature_flag.evaluation.reason";
21-
public static final String TELEMETRY_PROVIDER = "feature_flag.provider_name";
21+
public static final String TELEMETRY_REASON = "feature_flag.result.reason";
22+
public static final String TELEMETRY_PROVIDER = "feature_flag.provider.name";
2223
public static final String TELEMETRY_FLAG_SET_ID = "feature_flag.set.id";
2324
public static final String TELEMETRY_VERSION = "feature_flag.version";
2425

@@ -28,68 +29,64 @@ private Telemetry() {}
2829
public static final String TELEMETRY_FLAG_META_FLAG_SET_ID = "flagSetId";
2930
public static final String TELEMETRY_FLAG_META_VERSION = "version";
3031

31-
// OpenTelemetry event body.
32-
// Specification: https://opentelemetry.io/docs/specs/semconv/feature-flags/feature-flags-logs/
33-
public static final String TELEMETRY_BODY = "value";
34-
3532
public static final String FLAG_EVALUATION_EVENT_NAME = "feature_flag.evaluation";
3633

3734
/**
3835
* Creates an EvaluationEvent using the provided HookContext and ProviderEvaluation.
3936
*
4037
* @param hookContext the context containing flag evaluation details
41-
* @param providerEvaluation the evaluation result from the provider
38+
* @param evaluationDetails the evaluation result from the provider
4239
*
4340
* @return an EvaluationEvent populated with telemetry data
4441
*/
4542
public static EvaluationEvent createEvaluationEvent(
46-
HookContext<?> hookContext, ProviderEvaluation<?> providerEvaluation) {
43+
HookContext<?> hookContext, FlagEvaluationDetails<?> evaluationDetails) {
4744
EvaluationEvent.EvaluationEventBuilder evaluationEventBuilder = EvaluationEvent.builder()
4845
.name(FLAG_EVALUATION_EVENT_NAME)
4946
.attribute(TELEMETRY_KEY, hookContext.getFlagKey())
5047
.attribute(TELEMETRY_PROVIDER, hookContext.getProviderMetadata().getName());
5148

52-
if (providerEvaluation.getReason() != null) {
49+
if (evaluationDetails.getReason() != null) {
5350
evaluationEventBuilder.attribute(
54-
TELEMETRY_REASON, providerEvaluation.getReason().toLowerCase());
51+
TELEMETRY_REASON, evaluationDetails.getReason().toLowerCase());
5552
} else {
5653
evaluationEventBuilder.attribute(
5754
TELEMETRY_REASON, Reason.UNKNOWN.name().toLowerCase());
5855
}
5956

60-
if (providerEvaluation.getVariant() != null) {
61-
evaluationEventBuilder.attribute(TELEMETRY_VARIANT, providerEvaluation.getVariant());
57+
if (evaluationDetails.getVariant() != null) {
58+
evaluationEventBuilder.attribute(TELEMETRY_VARIANT, evaluationDetails.getVariant());
6259
} else {
63-
evaluationEventBuilder.bodyElement(TELEMETRY_BODY, providerEvaluation.getValue());
60+
evaluationEventBuilder.attribute(TELEMETRY_VALUE, evaluationDetails.getValue());
6461
}
6562

66-
String contextId = providerEvaluation.getFlagMetadata().getString(TELEMETRY_FLAG_META_CONTEXT_ID);
63+
String contextId = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_CONTEXT_ID);
6764
if (contextId != null) {
6865
evaluationEventBuilder.attribute(TELEMETRY_CONTEXT_ID, contextId);
6966
} else {
7067
evaluationEventBuilder.attribute(
7168
TELEMETRY_CONTEXT_ID, hookContext.getCtx().getTargetingKey());
7269
}
7370

74-
String setID = providerEvaluation.getFlagMetadata().getString(TELEMETRY_FLAG_META_FLAG_SET_ID);
71+
String setID = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_FLAG_SET_ID);
7572
if (setID != null) {
7673
evaluationEventBuilder.attribute(TELEMETRY_FLAG_SET_ID, setID);
7774
}
7875

79-
String version = providerEvaluation.getFlagMetadata().getString(TELEMETRY_FLAG_META_VERSION);
76+
String version = evaluationDetails.getFlagMetadata().getString(TELEMETRY_FLAG_META_VERSION);
8077
if (version != null) {
8178
evaluationEventBuilder.attribute(TELEMETRY_VERSION, version);
8279
}
8380

84-
if (Reason.ERROR.name().equals(providerEvaluation.getReason())) {
85-
if (providerEvaluation.getErrorCode() != null) {
86-
evaluationEventBuilder.attribute(TELEMETRY_ERROR_CODE, providerEvaluation.getErrorCode());
81+
if (Reason.ERROR.name().equals(evaluationDetails.getReason())) {
82+
if (evaluationDetails.getErrorCode() != null) {
83+
evaluationEventBuilder.attribute(TELEMETRY_ERROR_CODE, evaluationDetails.getErrorCode());
8784
} else {
8885
evaluationEventBuilder.attribute(TELEMETRY_ERROR_CODE, ErrorCode.GENERAL);
8986
}
9087

91-
if (providerEvaluation.getErrorMessage() != null) {
92-
evaluationEventBuilder.attribute(TELEMETRY_ERROR_MSG, providerEvaluation.getErrorMessage());
88+
if (evaluationDetails.getErrorMessage() != null) {
89+
evaluationEventBuilder.attribute(TELEMETRY_ERROR_MSG, evaluationDetails.getErrorMessage());
9390
}
9491
}
9592

0 commit comments

Comments
 (0)