Skip to content

Announcing a beta-version of datadog-statsd-schema gem, testers wanted! #309

@kigster

Description

@kigster

Folks - after realizing how disorganized metrics and tags can be within a single organization, I put together a new ruby gem - datadog-statsd-schema — which acts as an adapter or a wrapper around dogstatsd-ruby, but adds a layer of declarative schemas for both metric names, tags and tag values. It then allows you to pass such a schema to the Emitter class, with a configuration that controls what happens when a metric violates said schema.

Consider this example (provided in the examples folder of the gem):

require 'datadog/statsd'        # this gem
require 'datadog/statsd/schema' # the new gem

# This schema defines a namespace for marathon metrics and tags.
marathon_schema = Datadog.schema do
  namespace "marathon" do
    namespace "started" do
      tags do
        tag :course, values: %w[sf-marathon new-york]
        tag :length, values: [26.212, 42.195]
        tag :units, values: %w[miles km]
      end
      metrics do
        counter "total", description: "Marathon started"
        distribution "duration", description: "Marathon duration"
      end
    end
  end
end

# Emitter is simply a wrapper around Datadog::Statsd instance.
emitter = Datadog.emitter(
  "simple_emitter",
  schema: marathon_schema,
  validation_mode: :strict,
  tags: {
    course: "sf-marathon",
    length: 26.212,
    units: "miles"
  }
)

# We can now send metrics that are validated.
emitter.increment("marathon.started.total", by: 3, tags: { course: "new-york" })
emitter.increment("marathon.started.total", by: 8, tags: { course: "new-york" })

emitter.distribution("marathon.started.duration", 43.13, tags: { course: "new-york" })
emitter.distribution("marathon.started.duration", 41.01, tags: { course: "new-york" })

Here is an example of validations in action:

validations

  • Please try it out and provide some feedback!

  • And if you like the idea of pre declared and validated metrics, please leave a 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions