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

Add stdout exporter example for Logs. #1072

Closed
wants to merge 2 commits into from

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented May 23, 2023

Design discussion issue (if applicable) #

Changes

Add the stdout exporter example for Logs. The example will

  • Initialize TraceProvider and LoggerProvider
  • Initialize Tracer and Logger object
  • Create Span, and make it active(current)
  • Emit Log.
  • Make the Span inactive (implicitly end/export it).

This will export the Span, along with the Log. The Log will have the trace_id and span_id of currently active span.
Output example:

{"resourceLogs":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"unknown_service"}}]},"scopeLogs":[{"scope":{"name":"stdout-test"},"logRecords":[{"severityNumber":9,"body":{"stringValue":"test log"},"attributes":[],"droppedAttributesCount":0,"flags":1,"spanId":"abf95442ac326a3b","traceId":"6b3271b5c619652bc28ad70810e7f131"}]}]}]}

{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"unknown_service"}}]},"scopeSpans":[{"scope":{"name":"stdout-test"},"spans":[{"traceId":"6b3271b5c619652bc28ad70810e7f131","spanId":"abf95442ac326a3b","parentSpanId":"","name":"test_span","kind":1,"startTimeUnixNano":1684817629827077900,"endTimeUnixNano":1684817629827244600,"attributes":[{"key":"test_key","value":{"stringValue":"test_value"}}],"droppedAttributesCount":0,"droppedEventsCount":0,"droppedLinksCount":0,"status":{}}]}]}]}

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team May 23, 2023 04:55
@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (e9adef6) 50.9% compared to head (b5ca720) 50.9%.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1072   +/-   ##
=====================================
  Coverage   50.9%   50.9%           
=====================================
  Files        165     165           
  Lines      19689   19689           
=====================================
  Hits       10025   10025           
  Misses      9664    9664           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

let mut span = tracer.start("test_span");
span.set_attribute(KeyValue::new("test_key", "test_value"));
let span_active = mark_span_as_active(span);
let log_record = LogRecordBuilder::new()
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 we should not be showing this, as this is never intended for end-users to use like this. This could be part of a tutorial for "how to write own appenders", or shown with existing log api like in this PR: #1071

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 agree, but I think it is still helpful to have a vendor neutral example (with no external dependencies) using only core API and SDK - which would be useful to both - external developers who want to (somehow) use only the core api and sdk in their application, and the developers creating their own appenders/subscriber. We can add a disclaimer as comment for LogRecordBuilder that it is not recommended for front facing API if that helps.

Said that, I don't have strong opinion, and can close this PR if we all agree this not to be good showcase example :)

Copy link
Member

Choose a reason for hiding this comment

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

Options:

  1. If the intended audience is authors of new appenders, cover it in the docs, no need of example.
  2. Keep this, but explicitly warn at the top saying this is not for end users to call directly. They should use the existing Log APIs. (eg: slog,log,tracing...)

Copy link
Member

Choose a reason for hiding this comment

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

I'd go for option 1 as that seems least confusing for lower context people.

@lalitb
Copy link
Member Author

lalitb commented May 23, 2023

Closing this PR- as discussed, it is better to add documentation for Appender devs, instead of having a example.

@lalitb lalitb closed this May 23, 2023
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.

3 participants