@@ -50,32 +50,98 @@ composer require overtrue/laravel-open-telemetry
5050php artisan vendor:publish --provider=" Overtrue\LaravelOpenTelemetry\OpenTelemetryServiceProvider" --tag=" config"
5151```
5252
53- ### 📋 Configuration Categories
53+ ### ⚠️ Important: Environment Variable Configuration
54+
55+ ** OpenTelemetry SDK initializes before Laravel** , which means OpenTelemetry environment variables ** cannot be set in Laravel's ` .env ` file** . They must be set as ** server environment variables** .
56+
57+ ** Reference** : [ OpenTelemetry PHP Issue #1436 ] ( https://github.com/open-telemetry/opentelemetry-php/issues/1436 )
58+
59+ #### ✅ Correct Ways to Set Environment Variables
60+
61+ ** Option 1: Server Environment Variables**
62+ ``` bash
63+ # Set in your server environment
64+ export OTEL_PHP_AUTOLOAD_ENABLED=true
65+ export OTEL_SERVICE_NAME=my-laravel-app
66+ export OTEL_TRACES_EXPORTER=console
67+ ```
5468
55- #### 🟢 Required Configuration (Recommended)
69+ ** Option 2: Docker Environment**
70+ ``` yaml
71+ # docker-compose.yml
72+ services :
73+ app :
74+ environment :
75+ - OTEL_PHP_AUTOLOAD_ENABLED=true
76+ - OTEL_SERVICE_NAME=my-laravel-app
77+ - OTEL_TRACES_EXPORTER=console
78+ ` ` `
79+
80+ **Option 3: PHP-FPM Configuration**
81+ ` ` ` nginx
82+ # In your nginx server block
83+ location ~ \.php$ {
84+ fastcgi_param OTEL_PHP_AUTOLOAD_ENABLED "true";
85+ fastcgi_param OTEL_SERVICE_NAME "my-laravel-app";
86+ fastcgi_param OTEL_TRACES_EXPORTER "console";
87+ # ... other fastcgi_param directives
88+ }
89+ ```
90+
91+ ** Option 4: Apache Environment**
92+ ``` apache
93+ # In your Apache virtual host or .htaccess
94+ SetEnv OTEL_PHP_AUTOLOAD_ENABLED "true"
95+ SetEnv OTEL_SERVICE_NAME "my-laravel-app"
96+ SetEnv OTEL_TRACES_EXPORTER "console"
97+ ```
5698
57- These configurations have defaults but should be explicitly set:
99+ #### ❌ This Will NOT Work
58100
59101``` dotenv
60- # Basic Configuration - Highly Recommended
61- OTEL_ENABLED=true # Enable/disable package functionality
62- OTEL_SERVICE_NAME=my-laravel-app # Service name for identification
102+ # ❌ These in Laravel's .env file will be IGNORED by OpenTelemetry SDK
103+ OTEL_PHP_AUTOLOAD_ENABLED=true
104+ OTEL_SERVICE_NAME=my-laravel-app
105+ OTEL_TRACES_EXPORTER=console
63106```
64107
65- #### 🟡 Important Optional Configuration
108+ #### 💡 Laravel-Specific Configuration
66109
67- Configure based on your use case :
110+ Laravel-specific configurations (this package's features) ** can ** be set in ` .env ` because they are read by Laravel after initialization :
68111
69112``` dotenv
70- # SDK Behavior Control
71- OTEL_SDK_AUTO_INITIALIZE=true # Auto-initialize SDK (default: true)
72- OTEL_SERVICE_VERSION=1.0.0 # Service version (default: 1.0.0)
113+ # ✅ These work in Laravel's .env file (this package's configurations)
114+ OTEL_ENABLED=true
115+ OTEL_AUTO_TRACE_REQUESTS=true
116+ OTEL_IGNORE_PATHS=horizon*,telescope*
117+ OTEL_SENSITIVE_HEADERS=authorization,cookie
118+ ```
119+
120+ ### 📋 Configuration Categories
121+
122+ #### 🟢 OpenTelemetry SDK Configuration (Server Environment Variables)
123+
124+ These ** must be set as server environment variables** , not in Laravel's ` .env ` file:
125+
126+ ``` bash
127+ # Core OpenTelemetry SDK Configuration - Set as server environment variables
128+ export OTEL_PHP_AUTOLOAD_ENABLED=true # Enable auto-instrumentation
129+ export OTEL_SERVICE_NAME=my-laravel-app # Service name for identification
130+ export OTEL_TRACES_EXPORTER=console # Trace export method
131+ # OR for production
132+ export OTEL_TRACES_EXPORTER=otlp # Use OTLP exporter
133+ export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 # OTLP endpoint
134+ ```
135+
136+ #### 🟡 Laravel Package Configuration (Laravel .env File)
73137
74- # Exporter Configuration
75- OTEL_TRACES_EXPORTER=console # Trace export method (default: console)
76- # OR
77- OTEL_TRACES_EXPORTER=otlp # Use OTLP exporter
78- OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 # OTLP endpoint
138+ These ** can be set in Laravel's ` .env ` file** because they are read by this package:
139+
140+ ``` dotenv
141+ # This Package's Configuration - Can be set in Laravel's .env
142+ OTEL_ENABLED=true # Enable/disable this package's functionality
143+ OTEL_SDK_AUTO_INITIALIZE=false # Auto-initialize SDK fallback (default: false)
144+ OTEL_SERVICE_VERSION=1.0.0 # Service version (default: 1.0.0)
79145```
80146
81147#### 🔵 Fully Optional Configuration
@@ -108,36 +174,64 @@ OTEL_LOGS_EXPORTER=none # Logs export (default: none)
108174### 🚀 Configuration Examples by Use Case
109175
110176#### Scenario 1: Quick Start/Testing
177+
178+ ** Server Environment Variables:**
179+ ``` bash
180+ export OTEL_PHP_AUTOLOAD_ENABLED=true
181+ export OTEL_SERVICE_NAME=my-app
182+ export OTEL_TRACES_EXPORTER=console
183+ ```
184+
185+ ** Laravel .env file:**
111186``` dotenv
112- # Only need this one!
113187OTEL_ENABLED=true
114188```
115- Everything else uses defaults, spans output to console.
116189
117190#### Scenario 2: Production Environment (External Collector)
191+
192+ ** Server Environment Variables:**
193+ ``` bash
194+ export OTEL_PHP_AUTOLOAD_ENABLED=true
195+ export OTEL_SERVICE_NAME=my-production-app
196+ export OTEL_TRACES_EXPORTER=otlp
197+ export OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector.com:4318
198+ ```
199+
200+ ** Laravel .env file:**
118201``` dotenv
119202OTEL_ENABLED=true
120- OTEL_SERVICE_NAME=my-production-app
121203OTEL_SERVICE_VERSION=2.1.0
122- OTEL_TRACES_EXPORTER=otlp
123- OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector.com:4318
204+ OTEL_AUTO_TRACE_REQUESTS=true
124205```
125206
126207#### Scenario 3: Development Environment (Detailed Configuration)
208+
209+ ** Server Environment Variables:**
210+ ``` bash
211+ export OTEL_PHP_AUTOLOAD_ENABLED=true
212+ export OTEL_SERVICE_NAME=my-dev-app
213+ export OTEL_TRACES_EXPORTER=console
214+ ```
215+
216+ ** Laravel .env file:**
127217``` dotenv
128218OTEL_ENABLED=true
129- OTEL_SERVICE_NAME=my-dev-app
130- OTEL_TRACES_EXPORTER=console
131219OTEL_AUTO_TRACE_REQUESTS=true
132- OTEL_IGNORE_PATHS=_debugbar*,telescope*
220+ OTEL_IGNORE_PATHS=_debugbar*,telescope*,horizon*
133221OTEL_SENSITIVE_HEADERS=authorization,cookie,x-api-key
134222```
135223
136224#### Scenario 4: Disabled/Testing Environment
225+
226+ ** Server Environment Variables:**
227+ ``` bash
228+ # Can leave OpenTelemetry variables unset or set to false
229+ export OTEL_PHP_AUTOLOAD_ENABLED=false
230+ ```
231+
232+ ** Laravel .env file:**
137233``` dotenv
138234OTEL_ENABLED=false
139- # OR
140- OTEL_TRACES_EXPORTER=none
141235```
142236
143237### Official Auto-Instrumentation Configuration
@@ -254,24 +348,35 @@ This command will:
254348
255349If you see ` NonRecordingSpan ` or traces not being recorded:
256350
257- 1 . ** Check basic configuration:**
351+ 1 . ** Check OpenTelemetry SDK environment variables (server-level):**
352+ ``` bash
353+ # These must be server environment variables, NOT in .env
354+ export OTEL_PHP_AUTOLOAD_ENABLED=true
355+ export OTEL_SERVICE_NAME=my-app
356+ export OTEL_TRACES_EXPORTER=console
357+ ```
358+
359+ 2 . ** Check Laravel package configuration (.env file):**
258360 ``` dotenv
361+ # These can be in Laravel's .env file
259362 OTEL_ENABLED=true
260- OTEL_SDK_AUTO_INITIALIZE=true
363+ OTEL_SDK_AUTO_INITIALIZE=false
261364 ```
262365
263- 2 . ** Run the test command:**
366+ 3 . ** Run the test command:**
264367 ``` bash
265368 php artisan otel:test
266369 ```
267370
268- 3 . ** Check the output for specific guidance on missing configuration**
371+ 4 . ** Check the output for specific guidance on missing configuration**
269372
270373### Common Issues
271374
272- - ** Traces not appearing** : Ensure ` OTEL_TRACES_EXPORTER ` is set to ` console ` or ` otlp `
273- - ** Performance concerns** : Set ` OTEL_ENABLED=false ` in non-production environments if needed
274- - ** Too many traces** : Use ` OTEL_IGNORE_PATHS ` to filter out unwanted requests
375+ - ** Environment variables ignored** : Remember that OpenTelemetry SDK variables ** must be server environment variables** , not in Laravel's ` .env ` file. See [ issue #1436 ] ( https://github.com/open-telemetry/opentelemetry-php/issues/1436 )
376+ - ** Works with ` php artisan serve ` but not with nginx/apache** : This is because ` artisan serve ` reads ` .env ` differently. Set OpenTelemetry variables as server environment variables
377+ - ** Traces not appearing** : Ensure ` OTEL_TRACES_EXPORTER ` is set to ` console ` or ` otlp ` as a ** server environment variable**
378+ - ** Performance concerns** : Set ` OTEL_ENABLED=false ` in Laravel's ` .env ` file in non-production environments
379+ - ** Too many traces** : Use ` OTEL_IGNORE_PATHS ` in Laravel's ` .env ` file to filter out unwanted requests
275380
276381## Advanced Features
277382
0 commit comments