承接 maidomax/laravel-datadog-logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maidomax/laravel-datadog-logger

Composer 安装命令:

composer require maidomax/laravel-datadog-logger

包简介

A Laravel package for logging to Datadog via HTTP API

README 文档

README

A Laravel package that provides seamless integration with Datadog's HTTP log intake API, allowing you to send your Laravel application logs directly to Datadog for centralized logging and monitoring.

Features

  • 🚀 Easy integration with Laravel's logging system
  • 🌍 Support for all Datadog regions (US, EU, US3, US5)
  • 🏷️ Automatic tagging with service name and environment
  • ⚡ HTTP-based log transmission to Datadog
  • 🔧 Configurable via environment variables or config file
  • 📦 Auto-discovery support for Laravel 5.5+

Installation

You can install the package via Composer:

composer require maidomax/laravel-datadog-logger

Laravel Auto-Discovery

For Laravel 5.5+ with package auto-discovery enabled, the service provider will be automatically registered. For older versions, add the service provider to your config/app.php:

'providers' => [
    // ...
    Maidomax\DatadogLogger\DatadogLoggerServiceProvider::class,
],

Publish Configuration (Optional)

You can publish the configuration file to customize the package settings:

php artisan vendor:publish --tag=datadog-logger-config

This will create a config/datadog-logger.php file where you can customize the package settings.

Configuration

Environment Variables

Add the following environment variables to your .env file:

# Required: Your Datadog API Key
DATADOG_API_KEY=your_datadog_api_key_here

# Required: Datadog Log Intake URL for your region
# US: https://http-intake.logs.datadoghq.com/api/v2/logs
# EU: https://http-intake.logs.datadoghq.eu/api/v2/logs
# US3: https://http-intake.logs.us3.datadoghq.com/api/v2/logs
# US5: https://http-intake.logs.us5.datadoghq.com/api/v2/logs
DATADOG_LOG_INTAKE_URL=https://http-intake.logs.datadoghq.com/api/v2/logs

# Optional: Service name (defaults to 'laravel')
DATADOG_SERVICE=my-laravel-app

# Optional: Environment (defaults to APP_ENV, then 'local')
DATADOG_ENVIRONMENT=production

# Optional: Data source identifier (defaults to 'laravel')
DATADOG_SOURCE=my-custom-source

# Optional: HTTP timeout in seconds (defaults to 5)
DATADOG_TIMEOUT=10

# Optional: Connection timeout in seconds (defaults to 3)
DATADOG_CONNECTION_TIMEOUT=5

Laravel Logging Configuration

Add the Datadog logging channel to your config/logging.php:

'channels' => [
    // ... other channels

    'datadog' => [
        'driver' => 'datadog',
        'api_key' => env('DATADOG_API_KEY'),
        'intake_url' => env('DATADOG_LOG_INTAKE_URL'),
        'service' => env('DATADOG_SERVICE'),
        'environment' => env('DATADOG_ENVIRONMENT'),
        'source' => env('DATADOG_SOURCE'),
        'timeout' => env('DATADOG_TIMEOUT', 5),
        'connection_timeout' => env('DATADOG_CONNECTION_TIMEOUT', 3),
    ],

    // Example: Use Datadog alongside other logging channels
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'datadog'],
        'ignore_exceptions' => false,
    ],
],

Set Default Log Channel

Update your .env file to use the stack channel (or directly use datadog):

LOG_CHANNEL=stack

Usage

Once configured, you can use Laravel's standard logging methods and they will be sent to Datadog:

use Illuminate\Support\Facades\Log;

// These will be sent to Datadog (and other configured channels)
Log::emergency('System is down!');
Log::alert('High CPU usage detected');
Log::critical('Database connection failed');
Log::error('User authentication failed', ['user_id' => 123]);
Log::warning('Deprecated API endpoint used');
Log::notice('User logged in', ['user_id' => 456]);
Log::info('Order processed successfully', ['order_id' => 789]);
Log::debug('Debug information', ['data' => $someData]);

// Using specific channel
Log::channel('datadog')->info('This goes directly to Datadog');

// With context
Log::info('User action performed', [
    'user_id' => 123,
    'action' => 'purchase',
    'amount' => 99.99,
    'ip_address' => request()->ip(),
]);

Log Structure

Logs sent to Datadog will include the following fields:

  • ddsource: Data source identifier (configurable via DATADOG_SOURCE, defaults to "laravel")
  • ddtags: Environment and service tags (e.g., "env:production,service:my-app")
  • hostname: Server hostname
  • message: The log message
  • level: Log level (emergency, alert, critical, error, warning, notice, info, debug)
  • timestamp: Unix timestamp in milliseconds
  • context: Additional context data passed to the log
  • extra: Extra data from Monolog processors

Datadog Regions

This package supports all Datadog regions. Make sure to use the correct intake URL for your region:

Region Intake URL
US https://http-intake.logs.datadoghq.com/api/v2/logs
EU https://http-intake.logs.datadoghq.eu/api/v2/logs
US3 https://http-intake.logs.us3.datadoghq.com/api/v2/logs
US5 https://http-intake.logs.us5.datadoghq.com/api/v2/logs

Error Handling

If the package fails to send logs to Datadog (e.g., network issues, invalid API key), it will:

  1. Not throw exceptions to avoid breaking your application
  2. Log the error to PHP's error log for debugging
  3. Continue processing other log channels in your stack

Performance Considerations

  • Log transmission to Datadog is performed synchronously via HTTP requests
  • Failed requests have a configurable timeout (default 5 seconds) to prevent hanging
  • For high-volume applications or to avoid blocking, consider using a queue-based logging solution

Testing

composer test

Contributing

Please see CONTRIBUTING.md for details.

Security

If you discover any security-related issues, please email maidomax@yahoo.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE.md for more information.

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

maidomax/laravel-datadog-logger 适用场景与选型建议

maidomax/laravel-datadog-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「monolog」 「laravel」 「DataDog」 「observability」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 maidomax/laravel-datadog-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 maidomax/laravel-datadog-logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 maidomax/laravel-datadog-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 205
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-24