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

Remove TracerProvider.ApplyConfig and Config #1636

Closed
MrAlias opened this issue Mar 3, 2021 · 10 comments · Fixed by #1693
Closed

Remove TracerProvider.ApplyConfig and Config #1636

MrAlias opened this issue Mar 3, 2021 · 10 comments · Fixed by #1693
Labels
area:trace Part of OpenTelemetry tracing pkg:SDK Related to an SDK package
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Mar 3, 2021

The TracerProvider.ApplyConfig method and related Config are additions to the exposed API that likely are not needed nor ideal. The ApplyConfig method exists to update a TracerProvider's configuration. This is an optional part of the specification:

The TracerProvider MAY provide methods to update the configuration.

meaning that we could remove these items and remain compliant with the specification.

Removing this type and method from the exported API will be a reduction in the API. This will reduce the on-boarding load for new users wondering when they should be configuring the TracerProvider (at creation or after with this method). Additionally, it could reduce the maintenance burden if we decide in the future to add direct Setters for the Config fields to avoid issues similar to the ones identified in #1631 but would still need to support this exported method and type.

Removing these will remove functionality from the TracerProvider API, the user will no longer be able to update a configuration of a TracerProvider after it has been created. There do not seem to be any reasons why we would need to update this configuration after creation so this seems justified. If this functionality needs to be added back in we could likely do so in a way that better serves the intended purpose and one that doesn't leak internal implementation details of how the TracerProvider manages a synchronized configuration.

Proposal

Removing the ApplyConfig method from the TracerProvider will make the configuration of span limits, the default sampler, ID generators, and resource immutable. This means that the config field of the TracerProvider which holds an atomic value of the related Config could be flattened into the fields of a Config directly.

Removing this field and with the merging of #1633 the Config type will be unused. It can be removed when this is done.

@MrAlias MrAlias added pkg:SDK Related to an SDK package area:trace Part of OpenTelemetry tracing release:required-for-ga labels Mar 3, 2021
@MrAlias MrAlias added this to the RC1 milestone Mar 3, 2021
@MrAlias MrAlias changed the title Unexport TracerProvider Config Remove TracerProvider.ApplyConfig and Config Mar 3, 2021
@ijsong
Copy link
Contributor

ijsong commented Mar 10, 2021

If ApplyConfig is removed, we need a way to fix the invalid configuration or NewTracerProvider needs an error type in its return value.

ApplyConfig seems to guarantee some invariants of config for TracerProvider, for example, SpanLimits.EventCountLimit should be a positive value by the ApplyConfig. If only EventCountLimit field of the SpanLimits is zero or negative value, only other fields except EventCountLimit are applied. It seems not to be natural.

func (p *TracerProvider) ApplyConfig(cfg Config) {
p.mu.Lock()
defer p.mu.Unlock()
c := *p.config.Load().(*Config)
if cfg.DefaultSampler != nil {
c.DefaultSampler = cfg.DefaultSampler
}
if cfg.IDGenerator != nil {
c.IDGenerator = cfg.IDGenerator
}
if cfg.SpanLimits.EventCountLimit > 0 {
c.SpanLimits.EventCountLimit = cfg.SpanLimits.EventCountLimit
}

By the way, I can't find any rules of range of the SpanLimits.EventCountLimit in the specification. If SpanLimits.EventCountLimit is zero, does not the span allow any events in it?

ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 11, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 11, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 11, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 11, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 11, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
@seh
Copy link
Contributor

seh commented Mar 12, 2021

See this discussion from the "otel-go" channel in the "Cloud Native Computing Foundation" Slack workspace for a motivation for using the ApplyConfig method.

In particular, I'd like to be able to use tracing while discovering and collecting more fields for the Resource that the TracerProvider holds. I understand that it's possible that some spans would be published that would lack fields that I'd add to the Resource afterward.

@ijsong
Copy link
Contributor

ijsong commented Mar 12, 2021

@seh, Could you use Attributes of Span instead of Resource?
I'm not sure that your use case is aligned with the specification. Some explanation of Resource is in the specification.

A Resource is an immutable representation of the entity producing telemetry as Attributes. For example, a process producing telemetry that is running in a container on Kubernetes has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name. All three of these attributes can be included in the Resource. Note that there are certain "standard attributes" that have prescribed meanings.
...
When used with distributed tracing, a resource can be associated with the TracerProvider when the TracerProvider is created. That association cannot be changed later. When associated with a TracerProvider, all Spans produced by any Tracer from the provider MUST be associated with this Resource.

@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 12, 2021

@seh would a SetResource or MergeResource (or both?) method be preferred as a replacement?

@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 12, 2021

@ijsong while resources need to be immutable types, the one associated with the TracerProvider is not required to be static. We are removing the ApplyConfig method so that there are no misconfigurations (a blank field in an applied config will remove an existing value), but I don't see why we cannot replace it with more useful configuration options.

@seh
Copy link
Contributor

seh commented Mar 13, 2021

would a SetResource or MergeResource (or both?) method be preferred as a replacement?

As noted in the parallel Slack discussion, a MergeResource-style function would satisfy my needs. I'm looking only to augment the Resource used to initialize the TracerProvider, adding values that weren't yet available to me at that earlier initialization time.

@ijsong
Copy link
Contributor

ijsong commented Mar 13, 2021

Although I could misunderstand the specification, my understanding of it is like these:

  1. TracerProvider has configuration such as SpanProcessors, IdGenerator, SpanLimits, and Sampler.
  2. The configurations of TracerProvider may be mutable.
  3. Resource represents things that produce telemetry.
  4. Resource is immutable.
  5. Association between TracerProvider and Resource can't be changed.
  6. Having multiple TracerProvider is possible.

For 1,

Configuration (i.e., SpanProcessors, IdGenerator, SpanLimits and Sampler) MUST be managed solely by the TracerProvider and it MUST provide some way to configure all of them that are implemented in the SDK, at least when creating or initializing it.

For 2,

The TracerProvider MAY provide methods to update the configuration.

For 3 and 4,

A Resource is an immutable representation of the entity producing telemetry as Attributes.

For 5,

When used with distributed tracing, a resource can be associated with the TracerProvider when the TracerProvider is created. That association cannot be changed later.

For 6,

Thus, implementations of TracerProvider SHOULD allow creating an arbitrary number of TracerProvider instances.

According to these, creating a new TracerProvider with merging Resource seems to be a possible solution.

@ijsong
Copy link
Contributor

ijsong commented Mar 16, 2021

@MrAlias @seh
As @seh mentioned in the slack channel (https://cloud-native.slack.com/archives/C01NPAXACKT/p1615856400041700?thread_ts=1615512000.030100&cid=C01NPAXACKT), dynamic augmenting Resource seems to be difficult. But there is another way to augment attributes.

ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 16, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 17, 2021

When used with distributed tracing, a resource can be associated with the TracerProvider when the TracerProvider is created. That association cannot be changed later.

Yikes, 😬, that is not a normative requirement in the specification yet it seems it is commonly being interpreted as such. That's not great.

Based on the ambiguity, I agree we should take the conservative approach here and try and honor the possible interpretation that the author was trying to make a normative requirement here.

ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, removes `WithSDK` functions from them, instead, introduces new
functions, for instance, `WithResource`, `WithDefaultSampler`, and
`WithSpanLimits`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, replcae `WithSDK` with `WithSDKOptions`.

Resolves open-telemetry#1636.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, replcae `WithSDK` with `WithSDKOptions`.

Resolves open-telemetry#1636, open-telemetry#1705.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, replaces `WithSDK` with `WithSDKOptions`.

Resolves open-telemetry#1636, open-telemetry#1705.
ijsong added a commit to ijsong/opentelemetry-go that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, replaces `WithSDK` with `WithSDKOptions`.

Resolves open-telemetry#1636, open-telemetry#1705.
MrAlias pushed a commit that referenced this issue Mar 18, 2021
This patch removes `ApplyConfig` method and `Config` struct from
`go.opentelemetry.io/otel/sdk/trace` package.  To ensure valid config
for TracerProvider, it adds `ensureValidTracerProviderConfig` private
function.
Jaeger and Zipkin have been used the `Config` directly across package
boundaries. Since `Config` is removed, they can't use it. This change,
thus, replaces `WithSDK` with `WithSDKOptions`.

Resolves #1636, #1705.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing pkg:SDK Related to an SDK package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants