定制 apitoolkit/apitoolkit-laravel 二次开发

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

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

apitoolkit/apitoolkit-laravel

最新稳定版本:v2.0.5

Composer 安装命令:

composer require apitoolkit/apitoolkit-laravel

包简介

A PHP/Laravel SDK Wrapper for APIToolkit. It monitors incoming traffic, gathers the requests and sends the request to the apitoolkit servers.

README 文档

README

APItoolkit's Logo APItoolkit's Logo

Laravel SDK

APItoolkit SDK Join Discord Server APItoolkit Docs

APItoolkit is an end-to-end API and web services management toolkit for engineers and customer support teams. To integrate your Laravel (PHP) application with APItoolkit, you need to use this SDK to monitor incoming traffic, aggregate the requests, and then deliver them to the APItoolkit's servers.

Table of Contents

Installation

Kindly run the command below to install the apitoolkit-laravel sdk and required otel packages:

composer require \
    open-telemetry/sdk \
    open-telemetry/exporter-otlp \
    apitoolkit/apitoolkit-laravel

Setup Opentelemetry

Installing opentelemetry extension

After installing the necessary packages, you'll need to install the opentelemetry extention and add it to your php.ini file

pecl install opentelemetry

Then add it to your php.ini file like so.

[opentelemetry]
extension=opentelemetry.so

export the following opentelemetry variables

export OTEL_PHP_AUTOLOAD_ENABLED=true
export OTEL_SERVICE_NAME=your-service-name
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol.apitoolkit.io:4318
export OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}"
export OTEL_PROPAGATORS=baggage,tracecontext

Setup APItoolkit Middleware

Next, register the middleware in the app/Http/Kernel.php file under the correct middleware group (e.g., api) or at the root, like so. This creates a customs spans which captures and sends http request info such as headers, requests and repsonse bodies, matched route etc. for each request

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        'api' => [
            // Other middleware here...
            \APIToolkit\Http\Middleware\APIToolkit::class, // Initialize the APItoolkit client
        ],
    ];
}

Alternatively, if you want to monitor specific routes, you can register the middleware, like so:

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    protected $routeMiddleware = [
        // Other middleware here...
        'apitoolkit' => \APIToolkit\Http\Middleware\APIToolkit::class,
    ];
}

Then you can use the apitoolkit middleware in your routes like so:

Route::get('/', function () {
    return response()->json([
        'message' => 'Welcome to your new application!'
    ]);
})->middleware('apitoolkit');

Note

The {ENTER_YOUR_API_KEY_HERE} demo string should be replaced with the API key generated from the APItoolkit dashboard.


Important

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this SDK documentation.

Contributing and Help

To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:

License

This repository is published under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固