Skip to content

Commit

Permalink
add opentelemetry extension support (#593)
Browse files Browse the repository at this point in the history
* add opentelemetry extension support

* config sort

* cleanup build args

* Update docs

* Adjust custom extension overrides for opentelemetry

* Add tests

* Update README.md and remove windows limitation

* Fix windows static build for opentelemetry

---------

Co-authored-by: crazywhalecc <jesse2061@outlook.com>
  • Loading branch information
CyberLine and crazywhalecc authored Feb 6, 2025
1 parent f19e90a commit 21de1a2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 9 deletions.
7 changes: 7 additions & 0 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@
"zlib"
]
},
"opentelemetry": {
"support": {
"BSD": "wip"
},
"type": "external",
"source": "opentelemetry"
},
"parallel": {
"support": {
"BSD": "wip"
Expand Down
10 changes: 10 additions & 0 deletions config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,16 @@
"path": "LICENSE.txt"
}
},
"opentelemetry": {
"type": "url",
"url": "https://pecl.php.net/get/opentelemetry",
"path": "php-src/ext/opentelemetry",
"filename": "opentelemetry.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"parallel": {
"type": "url",
"url": "https://pecl.php.net/get/parallel",
Expand Down
11 changes: 9 additions & 2 deletions docs/en/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ here will describe how to check the errors by yourself and report Issue.
Problems with downloading resources are one of the most common problems with spc.
The main reason is that the addresses used for SPC download resources are generally the official website of the corresponding project or GitHub, etc.,
and these websites may occasionally go down and block IP addresses.
Currently, version 2.0.0 has not added an automatic retry mechanism, so after encountering a download failure,
you can try to call the download command multiple times. If you confirm that the address is indeed inaccessible,
After encountering a download failure,
you can try to call the download command multiple times.

When downloading extensions, you may eventually see errors like `curl: (56) The requested URL returned error: 403` which are often caused by github rate limiting.
You can verify this by adding `--debug` to the command and will see something like `[DEBU] Running command (no output) : curl -sfSL "https://api.github.com/repos/openssl/openssl/releases"`.

To fix this, [create](https://github.com/settings/tokens) a personal access token on GitHub and set it as an environment variable `GITHUB_TOKEN=<XXX>`.

If you confirm that the address is indeed inaccessible,
you can submit an Issue or PR to update the url or download type.

## Doctor Can't Fix Something
Expand Down
9 changes: 8 additions & 1 deletion docs/zh/guide/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
## 下载失败问题

下载资源问题是 spc 最常见的问题之一。主要是由于 spc 下载资源使用的地址一般均为对应项目的官方网站或 GitHub 等,而这些网站可能偶尔会宕机、屏蔽 IP 地址。
目前 2.0.0 版本还没有加入自动重试机制,所以在遇到下载失败后,可以多次尝试调用下载命令。如果确认地址确实无法正常访问,可以提交 Issue 或 PR 更新地址。
在遇到下载失败后,可以多次尝试调用下载命令。

当下载资源时,你可能最终会看到类似 `curl: (56) The requested URL returned error: 403` 的错误,这通常是由于 GitHub 限制导致的。
你可以通过在命令中添加 `--debug` 来验证,会看到类似 `[DEBU] Running command (no output) : curl -sfSL "https://api.github.com/repos/openssl/openssl/releases"` 的输出。

要解决这个问题,可以在 GitHub 上 [创建](https://github.com/settings/token) 一个个人访问令牌,并将其设置为环境变量 `GITHUB_TOKEN=<XXX>`

如果确认地址确实无法正常访问,可以提交 Issue 或 PR 更新地址。

## doctor 无法修复

Expand Down
41 changes: 41 additions & 0 deletions src/SPC/builder/extension/opentelemetry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
use SPC\util\GlobalEnvManager;

#[CustomExt('opentelemetry')]
class opentelemetry extends Extension
{
public function validate(): void
{
if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
throw new \RuntimeException('The opentelemetry extension requires PHP 8.0 or later');
}
}

public function patchBeforeBuildconf(): bool
{
if (PHP_OS_FAMILY === 'Windows') {
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/ext/opentelemetry/config.w32',
"EXTENSION('opentelemetry', 'opentelemetry.c otel_observer.c', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');",
"EXTENSION('opentelemetry', 'opentelemetry.c otel_observer.c', PHP_OPENTELEMETRY_SHARED, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');"
);
return true;
}
return false;
}

public function patchBeforeMake(): bool
{
// add -Wno-strict-prototypes
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
return true;
}
}
5 changes: 5 additions & 0 deletions src/globals/ext-tests/opentelemetry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

assert(function_exists('OpenTelemetry\Instrumentation\hook'));
13 changes: 7 additions & 6 deletions src/globals/test-extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@

// test php version
$test_php_version = [
// '8.1',
// '8.2',
// '8.3',
'8.1',
'8.2',
'8.3',
'8.4',
];

// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
$test_os = [
'macos-13',
'macos-14',
'ubuntu-latest',
// 'windows-latest',
'windows-latest',
];

// whether enable thread safe
Expand All @@ -39,8 +40,8 @@

// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'dio',
'Windows' => 'dio',
'Linux', 'Darwin' => 'opentelemetry',
'Windows' => 'opentelemetry',
};

// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
Expand Down

0 comments on commit 21de1a2

Please sign in to comment.