| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package profiles |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/consumer/xconsumer" |
| 10 |
"go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp" |
| 11 |
"go.opentelemetry.io/collector/receiver/otlpreceiver/internal/errors" |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
type Receiver struct { |
| 16 |
pprofileotlp.UnimplementedGRPCServer |
| 17 |
nextConsumer xconsumer.Profiles |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
func New(nextConsumer xconsumer.Profiles) *Receiver { |
| 22 |
return &Receiver{ |
| 23 |
nextConsumer: nextConsumer, |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
func (r *Receiver) Export(ctx context.Context, req pprofileotlp.ExportRequest) (pprofileotlp.ExportResponse, error) { |
| 29 |
td := req.Profiles() |
| 30 |
|
| 31 |
numProfiles := td.SampleCount() |
| 32 |
if numProfiles == 0 { |
| 33 |
return pprofileotlp.NewExportResponse(), nil |
| 34 |
} |
| 35 |
|
| 36 |
err := r.nextConsumer.ConsumeProfiles(ctx, td) |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if err != nil { |
| 44 |
return pprofileotlp.NewExportResponse(), errors.GetStatusFromError(err) |
| 45 |
} |
| 46 |
|
| 47 |
return pprofileotlp.NewExportResponse(), nil |
| 48 |
} |