{"id":17681862,"url":"https://github.com/jgaskins/datadog","last_synced_at":"2025-05-12T22:15:17.876Z","repository":{"id":143300806,"uuid":"304774170","full_name":"jgaskins/datadog","owner":"jgaskins","description":"Datadog client for APM tracing and metrics in Crystal","archived":false,"fork":false,"pushed_at":"2023-02-09T16:56:36.000Z","size":33,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-12T22:14:39.797Z","etag":null,"topics":["apm","crystal","datadog","distributed-tracing","instrumentation","metrics","monitoring","observability"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jgaskins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-17T01:33:35.000Z","updated_at":"2024-12-17T11:45:24.000Z","dependencies_parsed_at":"2023-04-14T05:23:04.602Z","dependency_job_id":null,"html_url":"https://github.com/jgaskins/datadog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fdatadog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fdatadog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fdatadog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Fdatadog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgaskins","download_url":"https://codeload.github.com/jgaskins/datadog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253831001,"owners_count":21971007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apm","crystal","datadog","distributed-tracing","instrumentation","metrics","monitoring","observability"],"created_at":"2024-10-24T09:12:21.810Z","updated_at":"2025-05-12T22:15:17.842Z","avatar_url":"https://github.com/jgaskins.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Datadog\n\nThis is a Crystal library providing an APM tracing client for [Datadog](https://datadoghq.com/).\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     datadog:\n       github: jgaskins/datadog\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"datadog\"\n\nDatadog.configure do |c|\n  # Define your service\n  c.service \"my-web-app\", type: \"http\"\n\n  # Define tags you want on every span\n  c.tags = Datadog::Span::Metadata {\n    \"environment\" =\u003e ENV[\"ENVIRONMENT\"],\n    \"k8s_pod\" =\u003e ENV[\"HOSTNAME\"],\n    \"k8s_deployment\" =\u003e ENV[\"HOSTNAME\"][/\\A\\w+-\\w+/],\n  }\n\n  # You can set up values for where to contact the Datadog agent.\n  # These are the defaults.\n  c.agent_host = ENV[\"DD_AGENT_HOST\"]\n  c.trace_agent_port = ENV[\"DD_TRACE_AGENT_PORT\"]\n  c.metrics_agent_port = ENV[\"DD_METRICS_AGENT_PORT\"]\nend\n```\n\n### Report spans to Datadog APM\n\n```crystal\ntags = Datadog::Span::Metadata {\n  \"user_id\" =\u003e context.user.try(\u0026.id),\n  # ...\n}\n\nDatadog.tracer.trace \"my.span.name\", resource: \"my.resource.name\", tags: tags do |span|\n  # do work here\nend\n```\n\nThis can get pretty verbose if you're instrumenting heavily. It might be worth defining a method for it:\n\n```crystal\ndef instrument(name, resource, tags = Datadog::Span::Metadata.new) do |span|\n  Datadog.tracer.trace name, resource: resource, tags: tags do |span|\n    yield span\n  end\nend\n```\n\nThen your code only needs to call this:\n\n```crystal\ninstrument \"my.span.name\", \"my.resource.name\" do |span|\n  # do work here\nend\n```\n\nIf most of your span names are the same with different resources, you can instrument it even more easily by setting a default `name`.\n\nNote: To enable the Datadog tracing, set this environment variable: `DD_TRACING_ENABLED=\"true\"`.\n\n### Report Datadog custom metrics\n\nDatadog custom metrics are handled via [Statsd](https://github.com/statsd/statsd). `Datadog.metrics` is currently implemented as a [`Statsd::Client`](https://github.com/miketheman/statsd.cr).\n\n```crystal\n# Set a value\nDatadog.metrics.gauge \"my.metric.name\", 1, tags: %w[key1:value1 key2:value2]\n\n# Increment or decrement a gauge\nDatadog.metrics.increment \"my.metric.name\", tags: %w[key1:value1 key2:value2]\nDatadog.metrics.increment \"my.metric.name\", tags: %w[key1:value1 key2:value2]\n\n# Set a counter\nDatadog.metrics.set \"my.metric.name\", 1\n\n# Report how long it takes to execute a block\nDatadog.metrics.time \"my.metric.name\" do\n  # ...\nend\n\n# Maintain a histogram for how long it takes to execute a block\nDatadog.metrics.histogram \"my.metric.name\" do\n  # ...\nend\n```\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/jgaskins/datadog/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Fdatadog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgaskins%2Fdatadog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Fdatadog/lists"}