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

[service/telemetry] Switch to a factory pattern #10001

Merged
merged 2 commits into from
May 21, 2024

Conversation

mx-psi
Copy link
Member

@mx-psi mx-psi commented Apr 19, 2024

Description

Switches service/telemetry to a factory pattern. To avoid adding a lot of public API in one go:

  1. the actual factory builder is in an internal package
  2. I have not added the CreateMeterProvider method yet

There are two goals with this: one is to make progress on #4970, the other is to allow initializing telemetry sooner:

Link to tracking issue

Updates #4970.

Testing

Updates existing tests to use NewFactory

@mx-psi mx-psi force-pushed the mx-psi/tel-factory branch 2 times, most recently from d9e2cdf to c5768de Compare April 19, 2024 12:25
@mx-psi mx-psi marked this pull request as ready for review April 19, 2024 12:26
@mx-psi mx-psi requested a review from a team as a code owner April 19, 2024 12:26
Copy link

codecov bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 62.77372% with 51 lines in your changes are missing coverage. Please review.

Project coverage is 91.30%. Comparing base (1d64ec4) to head (6bd178a).

❗ Current head 6bd178a differs from pull request most recent head 01d4ff1. Consider uploading reports for the commit 01d4ff1 to get more accurate results

Files Patch % Lines
service/telemetry/factory.go 31.25% 22 Missing ⚠️
service/telemetry/tracer.go 58.62% 9 Missing and 3 partials ⚠️
service/telemetry/internal/factory.go 74.07% 5 Missing and 2 partials ⚠️
service/telemetry/telemetry.go 0.00% 6 Missing ⚠️
service/service.go 63.63% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10001      +/-   ##
==========================================
- Coverage   91.65%   91.30%   -0.35%     
==========================================
  Files         356      364       +8     
  Lines       16843    16745      -98     
==========================================
- Hits        15437    15289     -148     
- Misses       1063     1117      +54     
+ Partials      343      339       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label May 15, 2024
@mx-psi mx-psi removed the Stale label May 15, 2024
Copy link
Contributor

@atoulme atoulme left a comment

Choose a reason for hiding this comment

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

LGTM. Feels like a nice clean up.

otelcol/unmarshaler.go Show resolved Hide resolved

// Fetch data for internal telemetry like instance id and sdk version to provide for internal telemetry.
res := resource.New(set.BuildInfo, cfg.Telemetry.Resource)
pcommonRes := pdataFromSdk(res)

logger := tel.Logger()
telFactory := telemetry.NewFactory()
Copy link
Member

Choose a reason for hiding this comment

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

To highlight the point above, I don't like making 2 calls to NewFactory

Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

I like this approach. It addresses #4970 in a way that feels consistent with the rest of our APIs.

// use the NewFactory to implement it.
type Factory interface {
// CreateDefaultConfig creates the default configuration for the telemetry.
// TODO: Should we just inherit from component.Factory?
Copy link
Contributor

Choose a reason for hiding this comment

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

component.Factory would feel a little more uniform, though it's not clear to me how much a telemetry Factory really resembles a component factory. In particular, components have types, as where I don't know whether a telemetry factory will have a type.

  1. Will we want to utilize multiple telemetry factories within a service?
  2. Do we think we may want to offer alternate factories and let users choose between them in the service config?

I think what's here is alright for now, I just wanted to start the discussion around this point.

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 I'd prefer not to depend on anything from component in here, since this struct this factory builds is not a component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed on not having a dependency on component, I think we'd want to consider what commonalities the two have and move all of those things into a shared package.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will we want to utilize multiple telemetry factories within a service?

I feel like the answer to that is no (but API users are still free to do that by building their own factory that glues the two together). The type could be useful for having a consistent way to refer to what telemetry factory you used in logs/telemetry.

Do we think we may want to offer alternate factories and let users choose between them in the service config?

Probably also no? You should be able to eventually configure this through the builder IMO, but after that the service::telemetry config section should only support the config from your telemetry factory.

@mx-psi
Copy link
Member Author

mx-psi commented May 17, 2024

I believe all remaining discussions are things I can solve while I continue working on #4970, so I will merge this right after we release v0.101.0

@mx-psi mx-psi merged commit b1579a5 into open-telemetry:main May 21, 2024
47 checks passed
@github-actions github-actions bot added this to the next release milestone May 21, 2024
andrzej-stencel pushed a commit to andrzej-stencel/opentelemetry-collector that referenced this pull request May 27, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Switches `service/telemetry` to a factory pattern. To avoid adding a lot
of public API in one go:
1. the actual factory builder is in an internal package
2. I have not added the `CreateMeterProvider` method yet

There are two goals with this: one is to make progress on open-telemetry#4970, the
other is to allow initializing telemetry sooner:

<!-- Issue number if applicable -->
#### Link to tracking issue
Updates open-telemetry#4970. 

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Updates existing tests to use `NewFactory`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants