Skip to content

Commit

Permalink
fixup: apply changes
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
  • Loading branch information
aepfli committed Jan 2, 2025
1 parent 3f109ba commit 871c825
Show file tree
Hide file tree
Showing 183 changed files with 4,707 additions and 3,910 deletions.
46 changes: 30 additions & 16 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@

<property name="charset" value="UTF-8"/>

<property name="severity" value="${org.checkstyle.google.severity}" default="warning"/>
<property name="severity" value="error"/>

<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/filefilters/index.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<module name="SuppressWarningsFilter"/>

<!-- https://checkstyle.org/filters/suppressionfilter.html -->
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
Expand All @@ -54,12 +51,28 @@

<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="100"/>
<property name="ignorePattern"
value="^package.*|^import.*|href\s*=\s*&quot;[^&quot;]*&quot;|http://|https://|ftp://"/>
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

<module name="SuppressWarningsFilter" />

<module name="TreeWalker">
<!-- needed for SuppressWarningsFilter -->
<module name="SuppressWarningsHolder" />

<module name="SuppressWarnings">
<property name="id" value="checkstyle:suppresswarnings"/>
</module>

<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
<property name="optional" value="true"/>
</module>

<module name="UnusedImports"/>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
Expand Down Expand Up @@ -282,12 +295,12 @@
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="2"/>
<property name="caseIndent" value="2"/>
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
<property name="arrayInitIndent" value="4"/>
</module>
<!-- Suppression for block code until we find a way to detect them properly
until https://github.com/checkstyle/checkstyle/issues/15769 -->
Expand All @@ -297,8 +310,9 @@
| //SLIST[not(parent::CASE_GROUP)]/SLIST/RCURLY"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="0"/>
<property name="ignoreFinal" value="true"/>
<property name="allowedAbbreviations" value="API" />
<property name="allowedAbbreviationLength" value="1"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
Expand Down Expand Up @@ -358,7 +372,6 @@
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
<module name="JavadocParagraph">
<property name="allowNewlineParagraph" value="false"/>
</module>
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
<module name="AtclauseOrder">
Expand All @@ -374,7 +387,8 @@
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="MissingJavadocMethod">
<property name="scope" value="protected"/>
<property name="scope" value="public"/>
<property name="minLineCount" value="2"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import dev.openfeature.sdk.ImmutableMetadata;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.opentelemetry.api.common.Attributes;
import lombok.Builder;
import lombok.Getter;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import lombok.Builder;
import lombok.Getter;

/**
* OpenTelemetry hook options.
*/
@Builder
@Getter
@SuppressFBWarnings(value = {"EI_EXPOSE_REP"}, justification = "Dimension list can be mutable")

@SuppressFBWarnings(
value = {"EI_EXPOSE_REP"},
justification = "Dimension list can be mutable")
public class MetricHookOptions {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dev.openfeature.contrib.hooks.otel;

import static dev.openfeature.contrib.hooks.otel.OTelCommons.REASON_KEY;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.flagKeyAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.providerNameAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.variantAttributeKey;

import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.FlagEvaluationDetails;
import dev.openfeature.sdk.Hook;
Expand All @@ -11,18 +16,12 @@
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.LongUpDownCounter;
import io.opentelemetry.api.metrics.Meter;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import static dev.openfeature.contrib.hooks.otel.OTelCommons.REASON_KEY;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.flagKeyAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.providerNameAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.variantAttributeKey;
import lombok.extern.slf4j.Slf4j;

/**
* OpenTelemetry metric hook records metrics at different {@link Hook} stages.
Expand Down Expand Up @@ -58,9 +57,9 @@ public MetricsHook(final OpenTelemetry openTelemetry) {
public MetricsHook(final OpenTelemetry openTelemetry, final MetricHookOptions options) {
final Meter meter = openTelemetry.getMeter(METER_NAME);

activeFlagEvaluationsCounter =
meter.upDownCounterBuilder(EVALUATION_ACTIVE_COUNT).setDescription("active flag evaluations counter")
.build();
activeFlagEvaluationsCounter = meter.upDownCounterBuilder(EVALUATION_ACTIVE_COUNT)
.setDescription("active flag evaluations counter")
.build();

evaluationRequestCounter = meter.counterBuilder(EVALUATION_REQUESTS_TOTAL)
.setDescription("feature flag evaluation request counter")
Expand All @@ -81,13 +80,17 @@ public MetricsHook(final OpenTelemetry openTelemetry, final MetricHookOptions op
extraDimensions = options.getExtraAttributes();
}


@Override
public Optional<EvaluationContext> before(HookContext ctx, Map hints) {
activeFlagEvaluationsCounter.add(+1, Attributes.of(flagKeyAttributeKey, ctx.getFlagKey()));

evaluationRequestCounter.add(+1, Attributes.of(flagKeyAttributeKey, ctx.getFlagKey(), providerNameAttributeKey,
ctx.getProviderMetadata().getName()));
evaluationRequestCounter.add(
+1,
Attributes.of(
flagKeyAttributeKey,
ctx.getFlagKey(),
providerNameAttributeKey,
ctx.getProviderMetadata().getName()));
return Optional.empty();
}

Expand All @@ -96,7 +99,8 @@ public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
final AttributesBuilder attributesBuilder = Attributes.builder();

attributesBuilder.put(flagKeyAttributeKey, ctx.getFlagKey());
attributesBuilder.put(providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.put(
providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.putAll(extraDimensions);

if (details.getReason() != null) {
Expand All @@ -122,7 +126,8 @@ public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
public void error(HookContext ctx, Exception error, Map hints) {
final AttributesBuilder attributesBuilder = Attributes.builder();
attributesBuilder.put(flagKeyAttributeKey, ctx.getFlagKey());
attributesBuilder.put(providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.put(
providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.putAll(extraDimensions);

evaluationErrorCounter.add(+1, attributesBuilder.build());
Expand All @@ -136,8 +141,8 @@ public void finallyAfter(HookContext ctx, Map hints) {
/**
* A helper to derive attributes from {@link DimensionDescription}.
*/
private static Attributes attributesFromFlagMetadata(final ImmutableMetadata flagMetadata,
final List<DimensionDescription> dimensionDescriptions) {
private static Attributes attributesFromFlagMetadata(
final ImmutableMetadata flagMetadata, final List<DimensionDescription> dimensionDescriptions) {
final AttributesBuilder builder = Attributes.builder();

for (DimensionDescription dimension : dimensionDescriptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dev.openfeature.contrib.hooks.otel;

import io.opentelemetry.api.common.AttributeKey;

import static io.opentelemetry.semconv.incubating.FeatureFlagIncubatingAttributes.FEATURE_FLAG_KEY;
import static io.opentelemetry.semconv.incubating.FeatureFlagIncubatingAttributes.FEATURE_FLAG_PROVIDER_NAME;
import static io.opentelemetry.semconv.incubating.FeatureFlagIncubatingAttributes.FEATURE_FLAG_VARIANT;

import io.opentelemetry.api.common.AttributeKey;

class OTelCommons {
// Define semantic conventions
// Refer - https://opentelemetry.io/docs/specs/otel/logs/semantic_conventions/feature-flags/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dev.openfeature.contrib.hooks.otel;

import static dev.openfeature.contrib.hooks.otel.OTelCommons.EVENT_NAME;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.flagKeyAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.providerNameAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.variantAttributeKey;

import dev.openfeature.sdk.FlagEvaluationDetails;
import dev.openfeature.sdk.Hook;
import dev.openfeature.sdk.HookContext;
Expand All @@ -8,15 +13,9 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;

import java.util.Map;
import java.util.function.Function;

import static dev.openfeature.contrib.hooks.otel.OTelCommons.EVENT_NAME;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.flagKeyAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.providerNameAttributeKey;
import static dev.openfeature.contrib.hooks.otel.OTelCommons.variantAttributeKey;

/**
* The OpenTelemetry hook provides a way to automatically add a feature flag evaluation to a span as a span event.
* Refer to <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/feature-flags.md">OpenTelemetry</a>
Expand Down Expand Up @@ -63,7 +62,8 @@ public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
final AttributesBuilder attributesBuilder = Attributes.builder();

attributesBuilder.put(flagKeyAttributeKey, ctx.getFlagKey());
attributesBuilder.put(providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.put(
providerNameAttributeKey, ctx.getProviderMetadata().getName());
attributesBuilder.put(variantAttributeKey, variant);
attributesBuilder.putAll(extraAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import dev.openfeature.sdk.ImmutableMetadata;
import io.opentelemetry.api.common.Attributes;
import java.util.function.Function;
import lombok.Builder;
import lombok.Getter;

import java.util.function.Function;

/**
* OpenTelemetry {@link TracesHook} options.
*/
Expand Down
Loading

0 comments on commit 871c825

Please sign in to comment.