承接 atatus/laravel-atatus 相关项目开发

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

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

atatus/laravel-atatus

Composer 安装命令:

composer require atatus/laravel-atatus

包简介

Atatus PHP Middleware for Laravel

README 文档

README

Atatus Laravel Middleware allows for the automatic capture of API calls and sends them to Atatus API analytics.

How to install

Via Composer

$ composer require atatus/laravel-atatus

or add 'atatus/laravel-atatus' to your composer.json file accordingly.

How to use

Add Service Provider

// In config/app.php

'providers' => [
  /*
   * Application Service Providers...
   */
    Atatus\Middleware\AtatusLaravelServiceProvider::class,
];

Add to Middleware

If website root is your API, add to the root level:

// In App/Http/Kernel.php

protected $middleware = [
  /*
   * The application's global HTTP middleware stack.
   *
   * These middleware are run during every request to your application.
   */
   \Atatus\Middleware\AtatusLaravel::class,
];

If you only want to add tracking for APIs under specific route group, add to your route group, but be sure to remove from the global middleware stack from above global list.

// In App/Http/Kernel.php

protected $middlewareGroups = [
  /**
   * The application's API route middleware group.
   */
   'api' => [
        //
        \Atatus\Middleware\AtatusLaravel::class,
    ],
];

To track only certain routes, use route specific middleware setup.

Publish the package config file

$ php artisan vendor:publish --provider="Atatus\Middleware\AtatusLaravelServiceProvider"

Setup config

Edit config/atatus.php file.

// In config/atatus.php

return [
    'logBody' => true,
    // 'debug' => false,
    // 'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
];

For other configuration options, see below.

Configuration options

You can define Atatus configuration options in the config/atatus.php file.

logBody

Type: Boolean Optional, Default true, Set to false to remove logging request and response body to Atatus.

debug

Type: Boolean Optional, Default false, Set to true to print debug messages using Illuminate\Support\Facades\Log

configClass

Type: String Optional, a string for the full path (including namespaces) to a class containing additional functions. The class can reside in any namespace, as long as the full namespace is provided.

example:

return [
    'logBody' => true,
    'debug' => false,
    'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
];

Configuration class (Optional)

Because configuration hooks and functions cannot be placed in the config/atatus.php file, these reside in a PHP class that you create. Set the path to this class using the configClass option. You can define any of the following hooks:

identifyUserId

Type: ($request, $response) => String Optional, a function that takes a $request and $response and return a string for userId. Atatus automatically obtains end userId via $request->user()['id'], In case you use a non standard way of injecting user into $request or want to override userId, you can do so with identifyUserId.

identifyCompanyId

Type: ($request, $response) => String Optional, a function that takes a $request and $response and return a string for companyId.

maskRequestBody

Type: $body => $body Optional, a function that takes a $body, which is an associative array representation of JSON, and returns an associative array with any information removed.

maskResponseBody

Type: $body => $body Optional, same as above, but for Responses.

Example config class

namespace MyApp\MyConfigs;

class CustomAtatusConfig
{

    public function maskRequestBody($body) {
      return $body;
    }

    public function maskResponseBody($body) {
      return $body;
    }

    public function identifyUserId($request, $response) {
      if (is_null($request->user())) {
        return null;
      } else {
        $user = $request->user();
        return $user['id'];
      }
    }

    public function identifyCompanyId($request, $response) {
      return "comp_acme_corporation";
    }

}
  • In your config/atatus.php file:
return [
    'logBody' => true,
    'debug' => false,
    'configClass' => 'MyApp\\MyConfigs\\CustomAtatusConfig'
]

Be sure to update cache after changing config:

If you enabled config cache, after you update the configuration, please be sure to run php artisan config:cache again to ensure configuration is updated.

Credits

  • Mixpanel's PHP client
  • Moesif Laravel Middlware
  • Jonny Pickett

The PHP JSON extension is required.

Make sure you install PHP with the JSON Extension enabled More Info.

atatus/laravel-atatus 适用场景与选型建议

atatus/laravel-atatus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.02k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-06-12