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

Cannot test all fields of a Record #5192

Closed
MrAlias opened this issue Apr 10, 2024 · 13 comments · Fixed by #5258
Closed

Cannot test all fields of a Record #5192

MrAlias opened this issue Apr 10, 2024 · 13 comments · Fixed by #5258
Assignees
Labels
area:logs Part of OpenTelemetry logs bug Something isn't working pkg:SDK Related to an SDK package
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Apr 10, 2024

The Record has both methods to return the Resource and Scope it was created with by the SDK. However, when testing from export packages (i.e. otlploghttp) it is not possible to set these values. Therefore, it is not possible to test real data from multiple sources in an exporter.

We are going to need to export a way to construct a Record with these values or add "Set" methods for them.

This will also apply to limits and the DroppedAttributes method when #5190 merges.

@MrAlias MrAlias added bug Something isn't working pkg:SDK Related to an SDK package area:logs Part of OpenTelemetry logs labels Apr 10, 2024
@pellared
Copy link
Member

pellared commented Apr 11, 2024

It is possible when constructing the "full" SDK logs pipeline (logger provider and simple processor). It has been designed this way to ensure encapsulation of the data which is supposed to be set by the SDK.

Yet, I see that it can be inconvenient for testing. The same problem would be for testing custom processors.

Notice we do not want the processor to be able to modify the resource nor the scope.

@pellared pellared changed the title Cannot test all fields of a Record SDK/log: Make testing of exporters and processors more convinent Apr 11, 2024
@pellared pellared added enhancement New feature or request and removed bug Something isn't working labels Apr 11, 2024
@MrAlias MrAlias changed the title SDK/log: Make testing of exporters and processors more convinent Cannot test all fields of a Record Apr 11, 2024
@MrAlias MrAlias added bug Something isn't working and removed enhancement New feature or request labels Apr 11, 2024
@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 11, 2024

It is possible when constructing the "full" SDK logs pipeline (logger provider and simple processor). It has been designed this way to ensure encapsulation of the data which is supposed to be set by the SDK.

Are you saying any external package that want to test their transforms needs to install a full SDK?

That seems less than ideal.

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 11, 2024

Notice we do not want the processor to be able to modify the resource nor the scope.

Sure, but we don't want the processor to modify anything without cloning it and they are still able to do that.

This may be a reason our API is not providing the interface we want.

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 11, 2024

It might make sense to migrate to something like NewSpanContext.

We could have a NewRecord method that accepts some kind of "RecordData" and we could have the Clone method accept the same.

@pellared
Copy link
Member

It is possible when constructing the "full" SDK logs pipeline (logger provider and simple processor). It has been designed this way to ensure encapsulation of the data which is supposed to be set by the SDK.

Are you saying any external package that want to test their transforms needs to install a full SDK?

I say that this is the current state. Thus this issue is not a bug but an enhancement.

That seems less than ideal.

I agree.

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 11, 2024

I say that this is the current state. Thus this issue is not a bug but an enhancement.

There is a missing set of fundamental functionality with the logs SDK. This deficit is why it is classified and tagged as a bug.

Adding addition enhancing functionality is not what this issue is about. It is asking to provide functionality to make this package fundamentally usable.

@pellared
Copy link
Member

pellared commented Apr 12, 2024

I think we could do something similar to #5195. The name could additionaly warn that it should be used only for testing exporters and processors like TestRecordBuilder.

My other idea is providing TestRecord type which embeds *Record and have SetResource and SetInstrumenationScope methods.

@pellared pellared self-assigned this Apr 12, 2024
@pellared pellared moved this from Todo to In Progress in Go: Logs (GA) Apr 12, 2024
@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 13, 2024

My other idea is providing TestRecord type which embeds *Record and have SetResource and SetInstrumenationScope methods.

Using names of types to try and restrict use has a bad smell to it. It does not use the semantics of the Go language to make the restrictions intended. It relies on users knowing what a Test thing is for and not abusing it.

We could just as easily add methods to the Record and comment that they shouldn't be used outside of testing.

I would rather explore changes to the Record API itself to see if we can design it in way that supports the use we want to promote and allows the functionality users will need from the API.

@pellared
Copy link
Member

pellared commented Apr 13, 2024

Maybe it would be better to have such functionality under sdk/log/logtest. I believe that @MrAlias also mentioned this idea during the SIG meeting. I think we could do this by copying record.go and record_test.go to logtest and adding SetResource and SetInstrumentationScope (and tests) in seperate files (e.g. testrecord.go and testrecord_test.go). It is possible to convert between types that have exactly same fields. See: https://go.dev/play/p/rMq8vtYDx5O.

From: #5200 (comment)

EDIT: This technique does not work across packages if there are unexported fields. #5215

@pellared
Copy link
Member

pellared commented Apr 16, 2024

I unassigned myself as currently I think have no good ideas on how to follow-up

I would rather explore changes to the Record API itself to see if we can design it in way that supports the use we want to promote and allows the functionality users will need from the API.

The only idea I currently have is to expand https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#readwritelogrecord with something more or less like:

A function receiving this as an argument MAY additionally be able to modify the following information added to the LogRecord:

However, I think it may be in conflict with open-telemetry/opentelemetry-specification#3902 (comment)

On the other hand, there is a precedence from the C++ Logs SDK

@MrAlias, thoughts?

@pellared
Copy link
Member

The problem will be also with limits, dropped attributes, attributes deduplication. I start to feel that it is better (more trustworthy) to test custom processors and exporters using it with a logger provider created in the test.

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 16, 2024

Notes from talk with @pellared

  • There is an implementation bug where a processor should get a read/write record
  • We want to restrict what processors can set so things like the limits, resource, or scope are not modified.
  • We need to be able to set all fields with the SDK
  • We also need a way to get records in export testing that have all fields settable
    • Go has not way to restrict access to methods of a type or functions in a package based on imports from tests
    • Given this lack of syntaxtic restriction we need to rely on conventions and documentation as best as possible
    • We need to partition whatever solution we come up with in its own package
      • In an sdk/log/logtest package we could provide wrappers around an SDK setup and a custom processor that testing packages can call and get a set of records based on any field setting they want
      • Alternatively in an sdk/log/logtest package we could reference a common sdk/interal package has a Record definition. There would be creation functions that would return a Record directly with any field set.
        • This indirection would add complexity to the package structure and may not include all side-effects the SDK would provide.

@MrAlias
Copy link
Contributor Author

MrAlias commented Apr 18, 2024

More things blocked by not allowing a way to set a record's limits: #5230

@github-project-automation github-project-automation bot moved this from In Progress to Done in Go: Logs (GA) Apr 25, 2024
@MrAlias MrAlias added this to the v1.27.0 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logs Part of OpenTelemetry logs bug Something isn't working pkg:SDK Related to an SDK package
Projects
Status: Done
2 participants