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

Define attributes for internal metrics in metadata.yaml #10801

Open
dmitryax opened this issue Aug 5, 2024 · 7 comments
Open

Define attributes for internal metrics in metadata.yaml #10801

dmitryax opened this issue Aug 5, 2024 · 7 comments
Assignees

Comments

@dmitryax
Copy link
Member

dmitryax commented Aug 5, 2024

Define all the attributes for internal metrics in the metadata.yaml similar to what we do for the scraper metrics.

Those attribute definitions should be used to generate documentation and helpers that replace the directly exposed counters with Record... functions.

For example:

Instead of

type TelemetryBuilder struct {
	ExporterSentSpans metric.Int64Counter
}

we would generate

type TelemetryBuilder struct {
	exporterSentSpans   metric.Int64Counter
}

// RecordExporterSentSpans adds a value to the ExporterSentSpans metric.
func (builder *TelemetryBuilder) RecordExporterSentSpans(ctx context.Context, value int64, exporter string) {
	builder.exporterSentSpans.Add(context.Background(), value, metric.WithAttributeSet(attribute.NewSet(attribute.String("exporter", exporter))))
}
@dmitryax dmitryax added this to the Self observability milestone Aug 5, 2024
@dmitryax
Copy link
Member Author

dmitryax commented Aug 5, 2024

@codeboten, please let me know if it makes sense

@dmitryax dmitryax changed the title Move attributes definition for internal metrics to metadata.yaml Define attributes for internal metrics in metadata.yaml Aug 5, 2024
@codeboten
Copy link
Contributor

100% i would like to move in that direction for all internal telemetry as well

@crobert-1
Copy link
Member

Just to confirm with the assignment, I'll work on this 👍

codeboten added a commit to codeboten/opentelemetry-collector that referenced this issue Aug 19, 2024
Part of open-telemetry#10801

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
codeboten added a commit to codeboten/opentelemetry-collector that referenced this issue Aug 21, 2024
Part of open-telemetry#10801

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
@crobert-1
Copy link
Member

crobert-1 commented Aug 27, 2024

Started working on this, just want to bring up a limitation of the upstream go.opentelemetry.io/otel/attribute package. As described in this issue's description, attributes are added to a telemetry metric using the go.opentelemetry.io/otel/attribute package's functionality of attribute.NewSet, passing in the correct KeyValue information.

However, KeyValue only supports a subset of valid attribute types that our metadaya.yaml supports.

From mdatagen's metadata schema:

type: <string|int|double|bool|bytes|slice|map>

Types supported by KeyValue can be seen here.

The missing types are as follows: bytes, slice, and map. I believe this is an existing limitation, unrelated to this change. However, it may be good to document this limitation in the metadata schema file.

Edit: I've submitted #10997 to clearly state this limitation in the schema.

bogdandrutu pushed a commit that referenced this issue Sep 4, 2024
…ric attributes (#10997)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
The context can be found
[here.](#10801 (comment))
Only a subset of attribute types are supported for `telemetry` metrics
vs. regular `metrics`. There's no instrumentation equivalent for
attributes of the type `bytes`, `slice`, and `map`.
@crobert-1
Copy link
Member

I've got most of the functionality working, but I'd like to make sure it's tested more thoroughly before going forward. My current plan is as follows:

  1. Introduce telemetry metric test to test each telemetry metric. This test is written manually, and the PR's purpose will be to agree on format of test.
  2. Convert test to be generated by mdatagen. This will result in telemetry metric tests for each component that has telemetry metrics defined in their metadata.yaml.
  3. Introduce behavior described in this issue.

My goal is to be able to have tests that ensure existing behavior of recording telemetry metrics and their attributes doesn't change as a result of this.

@bogdandrutu
Copy link
Member

This is good, but less than ideal. See #11365

The best performant way is to actually construct the full MeasurementOption (result of metric.WithAttributeSet(attribute.NewSet(attribute.String("exporter", exporter)))) otherwise if I am not mistaken you have 2 extra allocs.

@dmitryax
Copy link
Member Author

dmitryax commented Oct 9, 2024

The best performant way is to actually construct the full MeasurementOption (result of metric.WithAttributeSet(attribute.NewSet(attribute.String("exporter", exporter)))) otherwise if I am not mistaken you have 2 extra allocs.

This still should be possible to hide in the builder and provide the suggested simplified interface, right?

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

No branches or pull requests

4 participants