-
Notifications
You must be signed in to change notification settings - Fork 986
Update to opentelemetry-configuration 1.0.0-rc.3 #7861
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
Changes from 3 commits
3c0e39d
c5a268f
b5e73dd
02290c2
61fe08c
20d944a
10b06bd
3672a2d
032795e
bc11574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalComposableProbabilitySamplerModel; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalComposableSamplerModel; | ||
| import io.opentelemetry.sdk.extension.incubator.trace.samplers.ComposableSampler; | ||
| import java.util.Map; | ||
|
|
||
| final class ComposableSamplerFactory | ||
| implements Factory<ExperimentalComposableSamplerModel, ComposableSampler> { | ||
|
|
||
| private static final ComposableSamplerFactory INSTANCE = new ComposableSamplerFactory(); | ||
|
|
||
| private ComposableSamplerFactory() {} | ||
|
|
||
| static ComposableSamplerFactory getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public ComposableSampler create( | ||
| ExperimentalComposableSamplerModel model, DeclarativeConfigContext context) { | ||
| if (model.getAlwaysOn() != null) { | ||
| return ComposableSampler.alwaysOn(); | ||
| } | ||
| if (model.getAlwaysOff() != null) { | ||
| return ComposableSampler.alwaysOff(); | ||
| } | ||
| ExperimentalComposableProbabilitySamplerModel probability = model.getProbability(); | ||
| if (probability != null) { | ||
| Double ratio = probability.getRatio(); | ||
| if (ratio == null) { | ||
| ratio = 1.0d; | ||
| } | ||
| return ComposableSampler.probability(ratio); | ||
| } | ||
| Map.Entry<String, ?> keyValue = | ||
| FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "composable sampler"); | ||
| return context.loadComponent(ComposableSampler.class, keyValue.getKey(), keyValue.getValue()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,16 @@ | |
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigUtil.requireNullResource; | ||
|
|
||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
| import java.util.Map; | ||
|
|
||
| final class LogRecordExporterFactory implements Factory<LogRecordExporterModel, LogRecordExporter> { | ||
|
|
||
| private static final String RESOURCE_NAME = "log record exporter"; | ||
|
|
||
| private static final LogRecordExporterFactory INSTANCE = new LogRecordExporterFactory(); | ||
|
|
||
| private LogRecordExporterFactory() {} | ||
|
|
@@ -22,17 +26,37 @@ static LogRecordExporterFactory getInstance() { | |
| @Override | ||
| public LogRecordExporter create(LogRecordExporterModel model, DeclarativeConfigContext context) { | ||
|
|
||
| model.getAdditionalProperties().compute("otlp_http", (k, v) -> model.getOtlpHttp()); | ||
| model.getAdditionalProperties().compute("otlp_grpc", (k, v) -> model.getOtlpGrpc()); | ||
| model | ||
| .getAdditionalProperties() | ||
| .compute("otlp_file/development", (k, v) -> model.getOtlpFileDevelopment()); | ||
| model.getAdditionalProperties().compute("console", (k, v) -> model.getConsole()); | ||
| String key = null; | ||
| Object resource = null; | ||
|
|
||
| if (model.getOtlpHttp() != null) { | ||
| key = "otlp_http"; | ||
| resource = model.getOtlpHttp(); | ||
| } | ||
| if (model.getOtlpGrpc() != null) { | ||
| requireNullResource(resource, RESOURCE_NAME, model.getAdditionalProperties()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding strictness here to fail fast?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was to reproduce the max-1 check from the previous map/compute approach
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand the intent: if
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old implementation works because I was sort of cheating and moving all the well known exporter model definitions to additionalProperties.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed bc11574 which sort of reverts this change but does it without polluting Thinking about this, I need to go apply this pattern to SamplerFactory, LgRecordProcessorFactory, SpanProcessorFactory, TextMapPropagatorFactory, AggregationFactory. In all these cases, exactly one key value pair is expected but the implementations tolerate multiple. Will do this in a followup PR. |
||
| key = "otlp_grpc"; | ||
| resource = model.getOtlpGrpc(); | ||
| } | ||
| if (model.getOtlpFileDevelopment() != null) { | ||
| requireNullResource(resource, RESOURCE_NAME, model.getAdditionalProperties()); | ||
| key = "otlp_file/development"; | ||
| resource = model.getOtlpFileDevelopment(); | ||
| } | ||
| if (model.getConsole() != null) { | ||
| requireNullResource(resource, RESOURCE_NAME, model.getAdditionalProperties()); | ||
| key = "console"; | ||
| resource = model.getConsole(); | ||
| } | ||
| if (key == null || resource == null) { | ||
| Map.Entry<String, ?> keyValue = | ||
| FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), RESOURCE_NAME); | ||
| key = keyValue.getKey(); | ||
| resource = keyValue.getValue(); | ||
| } | ||
|
|
||
| Map.Entry<String, Object> keyValue = | ||
| FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "log record exporter"); | ||
| LogRecordExporter logRecordExporter = | ||
| context.loadComponent(LogRecordExporter.class, keyValue.getKey(), keyValue.getValue()); | ||
| context.loadComponent(LogRecordExporter.class, key, resource); | ||
| return context.addCloseable(logRecordExporter); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.