Git Product home page Git Product logo

plug_datadog_stats's Introduction

PlugDatadogStats

Provides a pre-plug to log request time, status, and integer-ignoring-URL-path to datadog.

Installation

You can install the plug directly from GitHub with these incantations in your mix.exs:

def application do
  [
    mod: {YourPlugBasedThing, []},
    applications: [
      ...
      :pre_plug,
    ]
  ]
end

def deps do
  [
    {:pre_plug, "~> 0.1.0"},
    {:plug_datadog_stats, github: "PagerDuty/plug_datadog_stats", ref: "1.0.0"},
  ]
end

In your config.exs:

config :plug_datadog_stats,
  histogram_name: "whatever.you.want.in.datadog.resp_time",
  count_name: "whatever.you.want.in.datadog.resp_count"

# Configure ExStatsD as per the ExStatsD docs.

And then e.g. in a Phoenix your_plug_based_thing/endpoint.ex:

defmodule YourPlugBasedThing.Endpoint do
  ...
  pre_plug PlugDatadogStats
  ...
end

Handling Non-standard Path Parameters

Sometimes we have paths that have path parameters that are not easily matchable using regular expressions.

A simple example would be this: /api/v1/status_service/slug/my-custom-slug-4

A more complex example might look like this: /api/v1/status_service/slug/my-custom-slug-4/views/my-user-readable-view-id

PlugDatadogStats will interpret each of these as a separate path and create a tag for all of them which is Not Desirable™.

To handle cases like this, you can pass the plug a path_normalize_fn option that explicitly matches on the path patterns you expect:

# This can be defined in any other module.  For this example it is defined in the
# same module that the plug is added to the pipeline
def path_param_override(["api", "v1", "status_service", "slug", _slug]) do
  ["api", "v1", "status_service", "slug", "SLUG"]
end

def path_param_override(path_info), do: path_info # be sure to include the base case

pre_plug PlugDatadogStats, path_normalize_fn: {__MODULE__, :path_param_override, []}

plug_datadog_stats's People

Contributors

alizain-pd avatar gotibhai avatar jevanspager avatar joelcrocker avatar pkwok avatar taavi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.