定制 justanalyticsapp/justanalytics-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

justanalyticsapp/justanalytics-php

Composer 安装命令:

composer require justanalyticsapp/justanalytics-php

包简介

JustAnalytics PHP SDK for distributed tracing, error tracking, logging, and infrastructure metrics

README 文档

README

Official PHP SDK for JustAnalytics — distributed tracing, error tracking, logging, and infrastructure metrics for PHP applications.

Requirements

  • PHP 8.1+
  • ext-json
  • ext-curl

Installation

composer require justanalyticsapp/justanalytics-php

Quick Start

use JustAnalytics\JustAnalytics;

JustAnalytics::init([
    'siteId' => 'your-site-id',
    'apiKey' => 'ja_sk_your_api_key',
    'serviceName' => 'my-php-app',
    'environment' => 'production',
]);

// Create spans
$result = JustAnalytics::startSpan('process-order', 'internal', [], function ($span) {
    $span->setAttribute('order.id', '12345');
    return processOrder();
});

// Capture exceptions
try {
    riskyOperation();
} catch (\Throwable $e) {
    JustAnalytics::captureException($e, ['tags' => ['module' => 'payments']]);
}

// Capture messages
JustAnalytics::captureMessage('User exceeded rate limit', 'warning');

// Set user context
JustAnalytics::setUser(['id' => 'user-123', 'email' => 'alice@example.com']);

// Set tags
JustAnalytics::setTag('feature', 'checkout');

// Flush at end of request
JustAnalytics::flush();

Laravel Integration

The SDK auto-discovers in Laravel via the service provider. Add your credentials to .env:

JUSTANALYTICS_SITE_ID=your-site-id
JUSTANALYTICS_API_KEY=ja_sk_your_api_key
JUSTANALYTICS_SERVICE_NAME=my-laravel-app

Publish the config file:

php artisan vendor:publish --tag=justanalytics-config

The middleware is auto-registered and creates server spans for every HTTP request.

Symfony Integration

Register the bundle in config/bundles.php:

return [
    JustAnalytics\Integrations\Symfony\JustAnalyticsBundle::class => ['all' => true],
];

Add configuration in config/packages/just_analytics.yaml:

just_analytics:
    site_id: '%env(JUSTANALYTICS_SITE_ID)%'
    api_key: '%env(JUSTANALYTICS_API_KEY)%'
    service_name: '%env(JUSTANALYTICS_SERVICE_NAME)%'

Guzzle Auto-Instrumentation

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use JustAnalytics\Integrations\Guzzle\GuzzleMiddleware;

$stack = HandlerStack::create();
$stack->push(GuzzleMiddleware::create(), 'justanalytics');

$client = new Client(['handler' => $stack]);

Configuration Options

Option Type Default Description
siteId string required Site ID from dashboard
apiKey string required API key (ja_sk_...)
serviceName string required Service identifier
environment string null Deployment environment
release string null Release/version
serverUrl string production URL JustAnalytics server
debug bool false Enable debug logging
enabled bool true Enable/disable SDK
async bool false Use shutdown function
maxBatchSize int 100 Max batch size
timeout int 5 HTTP timeout (seconds)

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固