Skip to content

Commit

Permalink
rename to launcher (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Jul 31, 2020
1 parent a6df1b2 commit d1b3c48
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Minimal setup
import "github.com/lightstep/otel-launcher-go/launcher"

func main() {
lightstepOtel := launcher.ConfigureOpentelemetry(
otel := launcher.ConfigureOpentelemetry(
launcher.WithServiceName("service-name"),
launcher.WithAccessToken("access-token"),
)
defer lightstepOtel.Shutdown()
defer otel.Shutdown()
}
```

Expand Down
46 changes: 23 additions & 23 deletions launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,84 +35,84 @@ import (
"google.golang.org/grpc/credentials"
)

type Option func(*LightstepConfig)
type Option func(*LauncherConfig)

// WithAccessToken configures the lightstep access token
func WithAccessToken(accessToken string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.AccessToken = accessToken
}
}

// WithMetricExporterEndpoint configures the endpoint for sending metrics via OTLP
func WithMetricExporterEndpoint(url string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.MetricExporterEndpoint = url
}
}

// WithSpanExporterEndpoint configures the endpoint for sending traces via OTLP
func WithSpanExporterEndpoint(url string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.SpanExporterEndpoint = url
}
}

// WithServiceName configures a "service.name" resource label
func WithServiceName(name string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.ServiceName = name
}
}

// WithServiceVersion configures a "service.version" resource label
func WithServiceVersion(version string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.ServiceVersion = version
}
}

// WithLogLevel configures the logging level for OpenTelemetry
func WithLogLevel(loglevel string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.LogLevel = loglevel
}
}

// WithSpanExporterInsecure permits connecting to the
// trace endpoint without a certificate
func WithSpanExporterInsecure(insecure bool) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.SpanExporterEndpointInsecure = insecure
}
}

// WithMetricExporterInsecure permits connecting to the
// metric endpoint without a certificate
func WithMetricExporterInsecure(insecure bool) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.MetricExporterEndpointInsecure = insecure
}
}

// WithResourceLabels configures attributes on the resource
func WithResourceLabels(attributes map[string]string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.resourceAttributes = attributes
}
}

// WithPropagators configures propagators
func WithPropagators(propagators []string) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.Propagators = propagators
}
}

// Configures a global error handler to be used throughout an OpenTelemetry instrumented project.
// See "go.opentelemetry.io/otel/api/global"
func WithErrorHandler(handler oterror.Handler) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.errorHandler = handler
}
}
Expand All @@ -123,7 +123,7 @@ type Logger interface {
}

func WithLogger(logger Logger) Option {
return func(c *LightstepConfig) {
return func(c *LauncherConfig) {
c.logger = logger
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ var (
defaultSpanExporterEndpoint = "ingest.lightstep.com:443"
)

type LightstepConfig struct {
type LauncherConfig struct {
SpanExporterEndpoint string `env:"OTEL_EXPORTER_OTLP_SPAN_ENDPOINT,default=ingest.lightstep.com:443"`
SpanExporterEndpointInsecure bool `env:"OTEL_EXPORTER_OTLP_SPAN_INSECURE,default=false"`
ServiceName string `env:"LS_SERVICE_NAME"`
Expand All @@ -167,7 +167,7 @@ type LightstepConfig struct {
errorHandler oterror.Handler
}

func validateConfiguration(c LightstepConfig) error {
func validateConfiguration(c LauncherConfig) error {
if len(c.ServiceName) == 0 {
serviceNameSet := false
for _, kv := range c.Resource.Attributes() {
Expand All @@ -194,8 +194,8 @@ func validateConfiguration(c LightstepConfig) error {
return nil
}

func newConfig(opts ...Option) LightstepConfig {
var c LightstepConfig
func newConfig(opts ...Option) LauncherConfig {
var c LauncherConfig
if err := envconfig.Process(context.Background(), &c); err != nil {
log.Fatal(err)
}
Expand All @@ -211,12 +211,12 @@ func newConfig(opts ...Option) LightstepConfig {
return c
}

type LightstepOpentelemetry struct {
type Launcher struct {
spanExporter *otlp.Exporter
}

// configurePropagators configures B3 propagation by default
func configurePropagators(c *LightstepConfig) error {
func configurePropagators(c *LauncherConfig) error {
propagatorsMap := map[string]propagation.HTTPPropagator{
"b3": apitrace.B3{},
"cc": correlation.CorrelationContext{},
Expand All @@ -240,7 +240,7 @@ func configurePropagators(c *LightstepConfig) error {
return nil
}

func newResource(c *LightstepConfig) *resource.Resource {
func newResource(c *LauncherConfig) *resource.Resource {
detector := resource.FromEnv{}
r, _ := detector.Detect(context.Background())
attributes := []kv.KeyValue{
Expand All @@ -267,7 +267,7 @@ func newResource(c *LightstepConfig) *resource.Resource {
return resource.New(attributes...)
}

func ConfigureOpentelemetry(opts ...Option) LightstepOpentelemetry {
func ConfigureOpentelemetry(opts ...Option) Launcher {
c := newConfig(opts...)

if c.LogLevel == "debug" {
Expand Down Expand Up @@ -318,12 +318,12 @@ func ConfigureOpentelemetry(opts ...Option) LightstepOpentelemetry {
if c.errorHandler != nil {
global.SetHandler(c.errorHandler)
}
return LightstepOpentelemetry{
return Launcher{
spanExporter: exporter,
}
}

func (ls *LightstepOpentelemetry) Shutdown() {
func (ls *Launcher) Shutdown() {
err := ls.spanExporter.Stop()
if err != nil {
log.Fatalf("failed to stop exporter: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions launcher/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestDefaultConfig(t *testing.T) {
kv.String("telemetry.sdk.version", version),
}

expected := LightstepConfig{
expected := LauncherConfig{
ServiceName: "",
ServiceVersion: "unknown",
SpanExporterEndpoint: "ingest.lightstep.com:443",
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestEnvironmentVariables(t *testing.T) {
kv.String("telemetry.sdk.version", version),
}

expected := LightstepConfig{
expected := LauncherConfig{
ServiceName: "test-service-name",
ServiceVersion: "test-service-version",
SpanExporterEndpoint: "satellite-url",
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestConfigurationOverrides(t *testing.T) {
kv.String("telemetry.sdk.version", version),
}

expected := LightstepConfig{
expected := LauncherConfig{
ServiceName: "override-service-name",
ServiceVersion: "override-service-version",
SpanExporterEndpoint: "override-satellite-url",
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestConfigurePropagators(t *testing.T) {

func TestConfigureResourcesAttributes(t *testing.T) {
os.Setenv("OTEL_RESOURCE_LABELS", "label1=value1,label2=value2")
config := LightstepConfig{
config := LauncherConfig{
ServiceName: "test-service",
ServiceVersion: "test-version",
}
Expand All @@ -311,7 +311,7 @@ func TestConfigureResourcesAttributes(t *testing.T) {
assert.Equal(t, expected, resource.Attributes())

os.Setenv("OTEL_RESOURCE_LABELS", "telemetry.sdk.language=test-language")
config = LightstepConfig{
config = LauncherConfig{
ServiceName: "test-service",
ServiceVersion: "test-version",
}
Expand All @@ -326,7 +326,7 @@ func TestConfigureResourcesAttributes(t *testing.T) {
assert.Equal(t, expected, resource.Attributes())

os.Setenv("OTEL_RESOURCE_LABELS", "service.name=test-service-b")
config = LightstepConfig{
config = LauncherConfig{
ServiceName: "test-service-b",
ServiceVersion: "test-version",
}
Expand Down

0 comments on commit d1b3c48

Please sign in to comment.