Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add public functions to export pdata to ExportXServicesRequest Protobuf bytes #1741

Merged
merged 11 commits into from
Sep 17, 2020
8 changes: 8 additions & 0 deletions consumer/pdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pdata
import (
"github.com/gogo/protobuf/proto"

otlpcollectorlogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"
)

Expand All @@ -42,6 +43,13 @@ func LogsToOtlp(ld Logs) []*otlplogs.ResourceLogs {
return *ld.orig
}

// LogsToOtlpProtoBytes converts the internal Logs to the OTLP Collector ExportLogsServiceRequest ProtoBuf bytes
func LogsToOtlpProtoBytes(ld Logs) ([]byte, error) {
return proto.Marshal(&otlpcollectorlogs.ExportLogsServiceRequest{
ResourceLogs: *ld.orig,
})
}

// NewLogs creates a new Logs.
func NewLogs() Logs {
orig := []*otlplogs.ResourceLogs(nil)
Expand Down
8 changes: 8 additions & 0 deletions consumer/pdata/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pdata
import (
"github.com/gogo/protobuf/proto"

otlpcollectormetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/metrics/v1"
)

Expand Down Expand Up @@ -51,6 +52,13 @@ func MetricsToOtlp(md Metrics) []*otlpmetrics.ResourceMetrics {
return *md.orig
}

// MetricsToOtlpProtoBytes converts the internal MetricData to the OTLP Collector ExportMetricsServiceRequest ProtoBuf bytes
func MetricsToOtlpProtoBytes(md Metrics) ([]byte, error) {
chenzhihao marked this conversation as resolved.
Show resolved Hide resolved
return proto.Marshal(&otlpcollectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: *md.orig,
})
}

// NewMetricData creates a new MetricData.
func NewMetrics() Metrics {
orig := []*otlpmetrics.ResourceMetrics(nil)
Expand Down
8 changes: 8 additions & 0 deletions consumer/pdata/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/gogo/protobuf/proto"

otlpcollectortrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
otlptrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/trace/v1"
)

Expand All @@ -41,6 +42,13 @@ func TracesToOtlp(td Traces) []*otlptrace.ResourceSpans {
return *td.orig
}

// TracesToOtlpProtoBytes converts the internal Traces to OTLP Collector ExportTraceServiceRequest ProtoBuf bytes
func TracesToOtlpProtoBytes(td Traces) ([]byte, error) {
return proto.Marshal(&otlpcollectortrace.ExportTraceServiceRequest{
ResourceSpans: *td.orig,
})
}

// NewTraces creates a new Traces.
func NewTraces() Traces {
orig := []*otlptrace.ResourceSpans(nil)
Expand Down