Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c893059
Add files via upload (#2)
hilmarf Sep 19, 2025
f19defd
Merge branch 'open-telemetry:main' into main
hilmarf Sep 23, 2025
d15d28f
Merge branch 'open-telemetry:main' into main
hilmarf Sep 25, 2025
d0bb63a
Merge branch 'open-telemetry:main' into main
hilmarf Sep 30, 2025
44d59ef
Merge branch 'open-telemetry:main' into main
hilmarf Oct 2, 2025
94d9d3b
Merge branch 'open-telemetry:main' into main
hilmarf Oct 7, 2025
19f22d7
Merge branch 'open-telemetry:main' into main
hilmarf Oct 9, 2025
de9238b
Merge branch 'open-telemetry:main' into main
hilmarf Oct 14, 2025
9400ec1
Merge branch 'open-telemetry:main' into main
hilmarf Oct 16, 2025
5702b74
add persistance storage to otlpreciver
Sep 26, 2025
bdecff3
fix test
Sep 29, 2025
1b1ea3f
prevent unkey literal
MJarmo Sep 29, 2025
f311879
fix lint errors
MJarmo Oct 7, 2025
b08af27
fix lint, and naming
MJarmo Oct 7, 2025
e802eb3
fix ctx pass
MJarmo Oct 7, 2025
903777e
fix losing logs
MJarmo Oct 16, 2025
6cf4492
fix tests
MJarmo Oct 16, 2025
b5eaa4b
rmv test debuq
MJarmo Oct 16, 2025
21ee440
Merge branch 'open-telemetry:main' into main
hilmarf Oct 21, 2025
1d6fcd2
Merge branch 'open-telemetry:main' into main
hilmarf Oct 23, 2025
c710608
Merge branch 'open-telemetry:main' into main
hilmarf Oct 24, 2025
df1bbbe
Merge branch 'open-telemetry:main' into main
hilmarf Oct 28, 2025
711f3ba
Merge branch 'open-telemetry:main' into main
hilmarf Oct 30, 2025
771d3fc
Merge branch 'open-telemetry:main' into main
hilmarf Nov 4, 2025
1932827
Merge branch 'open-telemetry:main' into main
hilmarf Nov 6, 2025
268e67b
Merge branch 'open-telemetry:main' into main
hilmarf Nov 11, 2025
671d8bc
Merge branch 'open-telemetry:main' into main
hilmarf Nov 13, 2025
40d97ce
Merge branch 'open-telemetry:main' into main
hilmarf Nov 18, 2025
20fd024
Merge branch 'open-telemetry:main' into main
hilmarf Nov 19, 2025
ceef80e
Merge branch 'open-telemetry:main' into main
hilmarf Nov 20, 2025
e95863b
Merge branch 'main' into AddStorageToOTLPREciver
hilmarf Nov 21, 2025
2894480
Merge branch 'open-telemetry:main' into main
hilmarf Nov 21, 2025
447a953
Merge branch 'main' into AddStorageToOTLPREciver
hilmarf Nov 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/sync-fork.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: sync-fork
on:
schedule:
- cron: '4 2 * * 4,2'
workflow_dispatch:
jobs:
sync-fork:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- run: gh repo sync $REPOSITORY -b $BRANCH_NAME
env:
GITHUB_TOKEN: ${{ secrets.SYNC_FORK_TOKEN }}
REPOSITORY: ${{ github.repository }}
BRANCH_NAME: ${{ github.ref_name }}
41 changes: 41 additions & 0 deletions receiver/otlpreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,47 @@ Several helper files are leveraged to provide additional capabilities automatica
- [TLS and mTLS settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md)
- [Auth settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configauth/README.md)

## Message Persistence

The OTLP receiver supports message persistence for failed sends. When enabled, failed messages are stored in persistent storage and retried automatically. This feature is useful for ensuring data reliability in case of temporary failures.

### Configuration

```yaml
receivers:
otlp:
protocols:
http:
endpoint: localhost:4318
persistence:
enabled: true
storage: file_storage
retry_interval: 5s
max_retries: 3

extensions:
file_storage:
directory: /tmp/otel-collector-storage
timeout: 1s

service:
extensions: [file_storage]
```

### Persistence Settings

- `enabled`: Enables message persistence for failed sends (default: false)
- `storage`: The ID of the storage extension to use for persistence
- `retry_interval`: The interval between retry attempts for failed sends (default: 5s)
- `max_retries`: The maximum number of retry attempts for failed sends (default: 3)

### How It Works

1. When a message fails to be processed, it is stored in the configured storage extension
2. A background retry worker periodically attempts to reprocess stored messages
3. Successful messages are removed from storage
4. Messages that exceed the maximum retry count are also removed from storage

## Writing with HTTP/JSON

The OTLP receiver can receive trace export calls via HTTP/JSON in addition to
Expand Down
22 changes: 22 additions & 0 deletions receiver/otlpreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net/url"
"path"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
Expand Down Expand Up @@ -58,10 +59,24 @@ type Protocols struct {
_ struct{}
}

// PersistenceConfig defines configuration for message persistence.
type PersistenceConfig struct {
// Enabled enables message persistence for failed sends.
Enabled bool `mapstructure:"enabled"`
// StorageID is the ID of the storage extension to use for persistence.
StorageID component.ID `mapstructure:"storage"`
// RetryInterval is the interval between retry attempts for failed sends.
RetryInterval time.Duration `mapstructure:"retry_interval"`
// prevent unkeyed literal initialization
_ struct{}
}

// Config defines configuration for OTLP receiver.
type Config struct {
// Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON).
Protocols `mapstructure:"protocols"`
// Persistence is the configuration for message persistence.
Persistence PersistenceConfig `mapstructure:"persistence"`
// prevent unkeyed literal initialization
_ struct{}
}
Expand All @@ -73,5 +88,12 @@ func (cfg *Config) Validate() error {
if !cfg.GRPC.HasValue() && !cfg.HTTP.HasValue() {
return errors.New("must specify at least one protocol when using the OTLP receiver")
}

if cfg.Persistence.Enabled {
if cfg.Persistence.RetryInterval <= 0 {
return errors.New("retry interval must be positive when persistence is enabled")
}
}

return nil
}
16 changes: 13 additions & 3 deletions receiver/otlpreceiver/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Config defines configuration for OTLP receiver.

### Config

| Name | Type | Default | Docs |
|-----------|---------------------------------------------------|------------|-------------------------------------------------------------------------------------------------------|
| protocols | [otlpreceiver-Protocols](#otlpreceiver-protocols) | <no value> | Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON). |
| Name | Type | Default | Docs |
|--------------|---------------------------------------------------|------------|-------------------------------------------------------------------------------------------------------|
| protocols | [otlpreceiver-Protocols](#otlpreceiver-protocols) | <no value> | Protocols is the configuration for the supported protocols, currently gRPC and HTTP (Proto and JSON). |
| persistence | [otlpreceiver-Persistence](#otlpreceiver-persistence) | <no value> | Persistence configuration for message storage and retry logic. |

### otlpreceiver-Protocols

Expand All @@ -16,6 +17,15 @@ Config defines configuration for OTLP receiver.
| grpc | [configgrpc-GRPCServerSettings](#configgrpc-grpcserversettings) | <no value> | GRPCServerSettings defines common settings for a gRPC server configuration. |
| http | [confighttp-HTTPServerSettings](#confighttp-httpserversettings) | <no value> | HTTPServerSettings defines settings for creating an HTTP server. |

### otlpreceiver-Persistence

| Name | Type | Default | Docs |
|----------------|--------|---------|-----------------------------------------------------------------------------------------|
| enabled | bool | false | Enables message persistence for failed sends. |
| storage | string | <no value> | The ID of the storage extension to use for persistence. |
| retry_interval | string | 5s | The interval between retry attempts for failed sends. |
| max_retries | int | 3 | The maximum number of retry attempts for failed sends. |

### configgrpc-GRPCServerSettings

| Name | Type | Default | Docs |
Expand Down
4 changes: 4 additions & 0 deletions receiver/otlpreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func createDefaultConfig() component.Config {
LogsURLPath: defaultLogsURLPath,
}),
},
Persistence: PersistenceConfig{
Enabled: false,
RetryInterval: 0,
},
}
}

Expand Down
45 changes: 35 additions & 10 deletions receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type otlpReceiver struct {
obsrepHTTP *receiverhelper.ObsReport

settings *receiver.Settings

// Persistence related fields
persistenceEnabled bool
persistenceManager *PersistenceManager
}

// newOtlpReceiver just creates the OpenTelemetry receiver services. It is the caller's
Expand All @@ -56,12 +60,13 @@ func newOtlpReceiver(cfg *Config, set *receiver.Settings) (*otlpReceiver, error)
set.TelemetrySettings = telemetry.DropInjectedAttributes(set.TelemetrySettings, telemetry.SignalKey)
set.Logger.Debug("created signal-agnostic logger")
r := &otlpReceiver{
cfg: cfg,
nextTraces: nil,
nextMetrics: nil,
nextLogs: nil,
nextProfiles: nil,
settings: set,
cfg: cfg,
nextTraces: nil,
nextMetrics: nil,
nextLogs: nil,
nextProfiles: nil,
settings: set,
persistenceEnabled: cfg.Persistence.Enabled,
}

var err error
Expand Down Expand Up @@ -131,13 +136,21 @@ func (r *otlpReceiver) startGRPCServer(ctx context.Context, host component.Host)
}

func (r *otlpReceiver) startHTTPServer(ctx context.Context, host component.Host) error {
// If HTTP is not enabled, nothing to start.
if !r.cfg.HTTP.HasValue() {
return nil
}

httpCfg := r.cfg.HTTP.Get()
httpMux := http.NewServeMux()

if r.persistenceEnabled {
var logsReceiver *logs.Receiver
if r.nextLogs != nil {
logsReceiver = logs.New(r.nextLogs, r.obsrepHTTP)
}
r.persistenceManager = NewPersistenceManager(r.cfg.Persistence, r.settings.Logger, logsReceiver)
}

if r.nextTraces != nil {
httpTracesReceiver := trace.New(r.nextTraces, r.obsrepHTTP)
httpMux.HandleFunc(string(httpCfg.TracesURLPath), func(resp http.ResponseWriter, req *http.Request) {
Expand All @@ -154,9 +167,15 @@ func (r *otlpReceiver) startHTTPServer(ctx context.Context, host component.Host)

if r.nextLogs != nil {
httpLogsReceiver := logs.New(r.nextLogs, r.obsrepHTTP)
httpMux.HandleFunc(string(httpCfg.LogsURLPath), func(resp http.ResponseWriter, req *http.Request) {
handleLogs(resp, req, httpLogsReceiver)
})
if r.persistenceManager != nil {
httpMux.HandleFunc(string(httpCfg.LogsURLPath), func(resp http.ResponseWriter, req *http.Request) {
handleLogsWithPersistence(resp, req, r.persistenceManager.logsReceiver, r.persistenceManager)
})
} else {
httpMux.HandleFunc(string(httpCfg.LogsURLPath), func(resp http.ResponseWriter, req *http.Request) {
handleLogs(resp, req, httpLogsReceiver)
})
}
}

if r.nextProfiles != nil {
Expand Down Expand Up @@ -216,6 +235,12 @@ func (r *otlpReceiver) Shutdown(ctx context.Context) error {
r.serverGRPC.GracefulStop()
}

if r.persistenceManager != nil {
if shutdownErr := r.persistenceManager.Shutdown(ctx); shutdownErr != nil {
err = errors.Join(err, shutdownErr)
}
}

r.shutdownWG.Wait()
return err
}
Expand Down
41 changes: 41 additions & 0 deletions receiver/otlpreceiver/otlphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"time"

"go.uber.org/zap"
"google.golang.org/grpc/status"

"go.opentelemetry.io/collector/internal/statusutil"
Expand Down Expand Up @@ -119,6 +120,46 @@ func handleLogs(resp http.ResponseWriter, req *http.Request, logsReceiver *logs.
writeResponse(resp, enc.contentType(), http.StatusOK, msg)
}

func handleLogsWithPersistence(resp http.ResponseWriter, req *http.Request, logsReceiver *logs.Receiver, persistenceManager *PersistenceManager) {
enc, ok := readContentType(resp, req)
if !ok {
return
}

body, ok := readAndCloseBody(resp, req, enc)
if !ok {
return
}

otlpReq, err := enc.unmarshalLogsRequest(body)
if err != nil {
writeError(resp, enc, err, http.StatusBadRequest)
return
}

otlpResp, err := logsReceiver.Export(req.Context(), otlpReq)
if err != nil {
persistenceManager.logger.Warn("Log processing failed, storing for retry",
zap.Error(err))
_, storeErr := persistenceManager.StoreMessage(req.Context(), body, enc.contentType(), "logs")
if storeErr != nil {
persistenceManager.logger.Error("Failed to store message for retry",
zap.Error(storeErr))
writeError(resp, enc, err, http.StatusInternalServerError)
return
}
writeResponse(resp, enc.contentType(), http.StatusAccepted, []byte(`{"message": "Logs queued for retry"}`))
return
}

msg, err := enc.marshalLogsResponse(otlpResp)
if err != nil {
writeError(resp, enc, err, http.StatusInternalServerError)
return
}
writeResponse(resp, enc.contentType(), http.StatusOK, msg)
}

func handleProfiles(resp http.ResponseWriter, req *http.Request, profilesReceiver *profiles.Receiver) {
enc, ok := readContentType(resp, req)
if !ok {
Expand Down
Loading
Loading