Skip to content

Conversation

@jack-berg
Copy link
Member

@jack-berg jack-berg commented Dec 8, 2025


@Override
public void onEmit(Context context, ReadWriteLogRecord logRecord) {
if (Loopback.isLoopback(context)) {
Copy link
Member

Choose a reason for hiding this comment

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

We also have to check in instrumentation for this I suppose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly, for example: https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/15572/files#diff-19adc31cb9699cb43b2c7701d9838a060a4ae299710b1e0b382493cfd1cc382f

There's another version of this we can consider as well:

  • Update the internals of SdkLoggerProvider such every call to LogRecordProcessor#onEmit(Context, ReadWriteLogRecord) has Context w/ otel.loopback=true (implicit and explicit context)
  • Update the internals of SdkLoggerProvider such that calls to SdkLogRecordBuilder#emit() short circuit if otel.loopback=true

I went with the approach you see here because modifying the internals of the SDK is arguably spec territory and this approach allows solving without changing internals.

Also, even if SdkLogRecordBuilder#emit() is short circuiting if otel.loopback=true, you'd still want instrumentation to short circuit to avoid the unnecessary mapping work which involves memory allocation.

But it might be worth to do both things. Or to start with this type of solution which doesn't rely on modying SDK internal, and later evolve if something lands in the spec.

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.

2 participants