-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align config options with OTEL, HTTP exporter
- Loading branch information
1 parent
c47abf6
commit c71e28e
Showing
7 changed files
with
247 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package opentelemetry | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" | ||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||
"go.opentelemetry.io/otel/sdk/metric" | ||
) | ||
|
||
func getExporter(cfg Config) (metric.Exporter, error) { | ||
// at the point of writing this code | ||
// ctx isn't used at any point in the exporter | ||
// later on, it could be used for the connection timeout | ||
ctx := context.Background() | ||
|
||
if cfg.ExporterType == grpcExporterType { | ||
return buildGRPCExporter(ctx, cfg) | ||
} | ||
|
||
if cfg.ExporterType == httpExporterType { | ||
return buildHTTPExporter(ctx, cfg) | ||
} | ||
|
||
return nil, errors.New("unsupported exporter type " + cfg.ExporterType + " specified") | ||
} | ||
|
||
func buildHTTPExporter(ctx context.Context, cfg Config) (metric.Exporter, error) { | ||
opts := []otlpmetrichttp.Option{ | ||
otlpmetrichttp.WithEndpoint(cfg.HTTPExporterEndpoint), | ||
otlpmetrichttp.WithURLPath(cfg.HTTPExporterURLPath), | ||
} | ||
|
||
if cfg.HTTPExporterInsecure.Bool { | ||
opts = append(opts, otlpmetrichttp.WithInsecure()) | ||
} | ||
|
||
return otlpmetrichttp.New(ctx, opts...) | ||
} | ||
|
||
func buildGRPCExporter(ctx context.Context, cfg Config) (metric.Exporter, error) { | ||
opt := []otlpmetricgrpc.Option{ | ||
otlpmetricgrpc.WithEndpoint(cfg.GRPCExporterEndpoint), | ||
} | ||
|
||
// TODO: give priority to the TLS | ||
if cfg.GRPCExporterInsecure.Bool { | ||
opt = append(opt, otlpmetricgrpc.WithInsecure()) | ||
} | ||
|
||
return otlpmetricgrpc.New(ctx, opt...) | ||
} |
Oops, something went wrong.