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 correlation identifier #660

Merged
merged 2 commits into from
Dec 19, 2018
Merged

Conversation

delner
Copy link
Contributor

@delner delner commented Dec 18, 2018

In many cases, such as logging, it may be useful to correlate trace IDs to other events or data streams, for easier cross referencing. This pull request adds active_correlation_ids to the tracer which produces a Datadog::Correlation::Identifier for the currently active trace, which can then be used to decorate other data sources.

An example of this for the purpose of logging:

require 'ddtrace'
require 'logger'

logger = Logger.new(STDOUT)
logger.progname = 'my_app'
logger.formatter  = proc do |severity, datetime, progname, msg|
  # Returns Datadog::Correlation::Identifier
  ids = Datadog.tracer.active_correlation_ids
  "[#{datetime}][#{progname}][#{severity}][dd.trace_id=#{ids.trace_id} dd.span_id=#{ids.span_id}] #{msg}\n"
end

# When a trace is active...
Datadog.tracer.trace('logging.example') do
  # And a warning is produced...
  logger.warn('This is a warning.')

  # Prints:
  # [2018-12-18 22:42:25 +0000][my_app][WARN][dd.trace_id=5963550561812073440 dd.span_id=2232727802607726424] This is a warning.
end

# When no trace is active...
# And a warning is produced...
logger.warn('This is a warning.')

# Prints:
# [2018-12-18 22:44:19 +0000][my_app][WARN][dd.trace_id= dd.span_id=] This is a warning.

@delner delner added core Involves Datadog core libraries feature Involves a product feature labels Dec 18, 2018
@delner delner added this to the 0.19.0 milestone Dec 18, 2018
@delner delner self-assigned this Dec 18, 2018
@delner delner force-pushed the feature/add_correlation_identifier branch from ec30e5e to db52e44 Compare December 18, 2018 22:56
@delner delner force-pushed the feature/add_correlation_identifier branch from db52e44 to dc6cbdb Compare December 18, 2018 23:03
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

Looks great!

@delner delner merged commit a66e427 into 0.19-dev Dec 19, 2018
@delner delner deleted the feature/add_correlation_identifier branch December 19, 2018 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries feature Involves a product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants