Overview
This page contains examples of the code block component.
Examples
Basic code block
example.js
const greeting = "Hello, world!";
console.log(greeting);
Collapsible
long_script.py
import requests
def fetch_metrics(api_key, app_key):
url = "https://api.datadoghq.com/api/v1/metrics"
headers = {
"DD-API-KEY": api_key,
"DD-APPLICATION-KEY": app_key,
}
response = requests.get(url, headers=headers)
return response.json()
if __name__ == "__main__":
data = fetch_metrics("YOUR_API_KEY", "YOUR_APP_KEY")
print(data)
Copy disabled
dangerous_command.sh
# This command is shown for reference only
dd-agent stop && rm -rf /etc/datadog-agent && dd-agent start
Wrap enabled
log_output.txt
2024-01-15T10:30:45.123Z [INFO] datadog.agent - Successfully connected to the Datadog intake endpoint at https://agent-intake.logs.datadoghq.com:443 with API key ending in ...abcd
All options combined
datadog.yaml
api_key: YOUR_API_KEY
site: datadoghq.com
logs_enabled: true
logs_config:
container_collect_all: true
auto_multi_line_detection: true
process_config:
process_collection:
enabled: true
Multiple languages
main.go
package main
import (
"fmt"
"github.com/DataDog/datadog-go/statsd"
)
func main() {
client, err := statsd.New("127.0.0.1:8125")
if err != nil {
fmt.Println(err)
return
}
client.Gauge("example.gauge", 42, nil, 1)
}
example.rb
require 'datadog/statsd'
statsd = Datadog::Statsd.new('localhost', 8125)
statsd.increment('example.counter')
statsd.gauge('example.gauge', 42)