diff --git a/README.md b/README.md index 8a4ecb0217be35f71e2096836e198dd3b76779b6..21c4ff6133896f8a62cfbc13fc8d4283737107c9 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,18 @@ As well as providing a semantic logger, this gem handles datadog telemetry assoc * metrics * statsd is automatically attached to datadog runtime metrics and may also be used for custom metrics. +### Sending metrics + +Ensure the metric name is in the format: `nexus.{component}.{major}.{minor}` + +Where _major and minor_ are specific to the component logic e.g. `nexus.uploads.clamscan.pass` + +For example, to increment a count: + +``` +NexusSemanticLogger.metrics.increment('nexus.users.registration.complete') +``` + # Local gem development Steps to run this gem from local sources in one the nexus 'staged build' rails components: diff --git a/lib/nexus_semantic_logger.rb b/lib/nexus_semantic_logger.rb index 6867bf49bf6fd7932ac74fe8386c1cecd3e92349..99e64941cebda069325783b9bf8160ea063819ae 100644 --- a/lib/nexus_semantic_logger.rb +++ b/lib/nexus_semantic_logger.rb @@ -6,4 +6,9 @@ require 'nexus_semantic_logger/datadog_singleton' require 'nexus_semantic_logger/datadog_tracer' module NexusSemanticLogger + + # Get application wide object for sending metrics. + def metrics + DatadogSingleton.instance + end end diff --git a/lib/nexus_semantic_logger/datadog_singleton.rb b/lib/nexus_semantic_logger/datadog_singleton.rb index c270974a3e7b02c971169b00bed2ab2a3432713a..927b26a59e83bae22faff18fbd8130c27c68687b 100644 --- a/lib/nexus_semantic_logger/datadog_singleton.rb +++ b/lib/nexus_semantic_logger/datadog_singleton.rb @@ -3,7 +3,8 @@ require 'singleton' module NexusSemanticLogger # Application wide location to get datadog objects. - # Can be moved to its own gem in future, and there is scope to make the usage code even leaner. + # dogstatsd-ruby maintains its own queue and thread for flushing, so the client code should never create its + # own statsd instance. class DatadogSingleton include Singleton attr_accessor :statsd, :tags