Skip to content

Commit cbe75d4

Browse files
Add configuration, adapters, publishing support, and documentation
- Implemented `pkg/config` to load Laravel-style `.env` configuration. - Added `pkg/database` factory for MySQL and PostgreSQL connections. - Added `pkg/cache` adapters for Redis, Memcached, and Database. - Updated `pkg/console` to auto-configure `queue:work` driver based on config. - Implemented `pkg/queue` Publisher for dispatching Laravel jobs. - Added SQS driver support. - Configured CI release workflow using `googleapis/release-please-action`. - Updated database driver tests to match new config structure. - Fixed linter errors in cache and worker packages. - Added documentation for registering job handlers in `docs/register_jobs.md` and logging in `docs/logging.md`. - Updated README.md to reference new docs. - Added example usage in `cmd/worker/main.go`.
1 parent f419c44 commit cbe75d4

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ For detailed package documentation, see [doc.go](doc.go) or run `go doc github.c
2323
For AI agents or developers needing a quick overview of the codebase structure and import paths, refer to [AGENTS.md](AGENTS.md).
2424

2525
See [docs/register_jobs.md](docs/register_jobs.md) for details on registering job handlers.
26+
See [docs/logging.md](docs/logging.md) for details on using the integrated logger and tracing.
2627

2728
## Usage
2829

docs/logging.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Logging and Tracing
2+
3+
The `laravel-go` library provides integrated structured logging (using `zerolog`) and distributed tracing (using `OpenTelemetry`).
4+
5+
## Trace IDs and Span IDs
6+
7+
When a job is processed, the worker automatically:
8+
1. Starts a new OpenTelemetry trace.
9+
2. Creates a structured logger attached to the context.
10+
3. Injects the `trace_id` and `job_id` into the logger.
11+
12+
This ensures that every log message generated during the job execution is automatically tagged with the Trace ID, allowing you to correlate logs across different services or even within a single job execution.
13+
14+
## Using the Logger
15+
16+
To use the logger in your job handlers, you should retrieve it from the context using `telemetry.LoggerFromContext(ctx)`.
17+
18+
### Example
19+
20+
```go
21+
package main
22+
23+
import (
24+
"context"
25+
"github.com/pixelvide/laravel-go/pkg/queue"
26+
"github.com/pixelvide/laravel-go/pkg/telemetry"
27+
)
28+
29+
func ProcessOrder(ctx context.Context, job *queue.Job) error {
30+
// 1. Get the logger from the context
31+
// This logger already has "trace_id" and "job_uuid" fields set.
32+
logger := telemetry.LoggerFromContext(ctx)
33+
34+
orderID := job.GetArg("orderId")
35+
36+
// 2. Log messages
37+
// These logs will include the trace context automatically.
38+
logger.Info().
39+
Any("order_id", orderID).
40+
Msg("Starting to process order")
41+
42+
if err := processOrder(orderID); err != nil {
43+
logger.Error().Err(err).Msg("Failed to process order")
44+
return err
45+
}
46+
47+
logger.Info().Msg("Order processed successfully")
48+
return nil
49+
}
50+
```
51+
52+
### Log Output Example
53+
54+
The output will look something like this (formatted for readability):
55+
56+
```json
57+
{
58+
"level": "info",
59+
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
60+
"job_uuid": "550e8400-e29b-41d4-a716-446655440000",
61+
"job_name": "App\\Jobs\\ProcessOrder",
62+
"order_id": 12345,
63+
"message": "Starting to process order",
64+
"time": "2023-10-27T10:00:00Z"
65+
}
66+
```
67+
68+
## Configuring Telemetry
69+
70+
The telemetry system is initialized automatically when using the `queue:work` command. You can customize the behavior by setting the global logger or tracer provider in your application setup if needed, but the default setup is sufficient for most use cases.

0 commit comments

Comments
 (0)