nginxModules.otel: init at 0.1.2

Assisted-by: Claude:claude-fable-5-1
This commit is contained in:
Ilan Joselevich
2026-09-21 14:50:11 +02:00
parent dba0cf96a9
commit c3d9063e08
3 changed files with 128 additions and 0 deletions

View File

@@ -1253,6 +1253,7 @@ in
nginx-modsecurity = runTest ./nginx-modsecurity.nix;
nginx-moreheaders = runTest ./nginx-moreheaders.nix;
nginx-njs = runTest ./nginx-njs.nix;
nginx-otel = runTest ./nginx-otel.nix;
nginx-proxyprotocol = runTest ./nginx-proxyprotocol/default.nix;
nginx-pubhtml = runTest ./nginx-pubhtml.nix;
nginx-redirectcode = runTest ./nginx-redirectcode.nix;

View File

@@ -0,0 +1,56 @@
{
name = "nginx-otel";
nodes.machine =
{ pkgs, ... }:
{
services.opentelemetry-collector = {
enable = true;
settings = {
receivers.otlp.protocols.grpc.endpoint = "127.0.0.1:4317";
exporters.debug.verbosity = "detailed";
service.pipelines.traces = {
receivers = [ "otlp" ];
exporters = [ "debug" ];
};
};
};
services.nginx = {
enable = true;
additionalModules = [ pkgs.nginxModules.otel ];
commonHttpConfig = ''
otel_exporter {
endpoint localhost:4317;
}
otel_service_name "nginx-test";
otel_trace on;
'';
virtualHosts."localhost".locations."/".extraConfig = ''
otel_trace_context propagate;
otel_span_name "handle";
return 200 "otel-ok";
'';
};
};
testScript =
{ nodes, ... }:
let
cfg = nodes.machine.services.nginx;
in
''
machine.wait_for_unit("opentelemetry-collector")
machine.wait_for_open_port(4317)
machine.wait_for_unit("nginx")
machine.wait_for_open_port(80)
machine.succeed("test -e ${cfg.package}/modules/ngx_otel_module.so")
machine.succeed("grep -F ngx_otel_module.so ${cfg.package}/etc/nginx/dynamic-modules.conf")
response = machine.wait_until_succeeds("curl -fsS http://127.0.0.1/")
t.assertIn("otel-ok", response)
machine.wait_until_succeeds("journalctl -u opentelemetry-collector --grep 'service.name: Str\\(nginx-test\\)'")
machine.wait_until_succeeds("journalctl -u opentelemetry-collector --grep 'Name +: handle'")
'';
}

View File

@@ -0,0 +1,71 @@
{
abseil-cpp,
c-ares,
cmake,
fetchFromGitHub,
grpc,
lib,
mkNginxPlugin,
nixosTests,
nlohmann_json,
openssl,
opentelemetry-cpp,
pkg-config,
protobuf,
re2,
zlib,
}:
mkNginxPlugin (finalAttrs: {
pname = "otel";
version = "0.1.2";
src = fetchFromGitHub {
owner = "nginxinc";
repo = "nginx-otel";
tag = "v${finalAttrs.version}";
hash = "sha256-pGe+1nPH8zUQhcyVxH5/nxwNFMsoOYCUecuDVs1rS4o=";
};
# nginx-otel can only be loaded dynamically.
dynamic = true;
nativeBuildInputs = [
cmake
pkg-config
protobuf
grpc
];
buildInputs = [
grpc
protobuf
opentelemetry-cpp
c-ares
re2
abseil-cpp
nlohmann_json
openssl
zlib
];
# Read by the module's config script. nginx's install step does not know
# about the cmake-built .so, so cmake writes it into the modules dir itself.
preConfigure = ''
export NGX_OTEL_CMAKE_OPTS="-DNGX_OTEL_GRPC=package -DNGX_OTEL_SDK=package -DNGX_OTEL_PROTO_DIR=${opentelemetry-cpp.opentelemetry-proto} -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$out/modules"
'';
passthru = {
# cmake's setup hook would replace nginx's configurePhase.
forNginx.dontUseCmakeConfigure = true;
tests = { inherit (nixosTests) nginx-otel; };
};
meta = {
description = "OpenTelemetry support for nginx";
homepage = "https://github.com/nginxinc/nginx-otel";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ kranzes ];
};
})