func NewEnvInjector()

in tracing/env_injector.go [24:59]


func NewEnvInjector(opts ...EnvInjectorOption) EnvInjector {
	/* config not yet used */
	applyEnvInjectorOptions(opts)

	return func(ctx context.Context, env []string) []string {
		envMap := map[string]string{}

		// Pass the Correlation-ID through the environment if set
		correlationID := correlation.ExtractFromContext(ctx)
		if correlationID != "" {
			envMap[envCorrelationIDKey] = correlationID
		}

		// Also include the GITLAB_TRACING configuration so that
		// the child process knows how to configure itself
		v, ok := os.LookupEnv(tracingEnvKey)
		if ok {
			envMap[tracingEnvKey] = v
		}

		span := opentracing.SpanFromContext(ctx)
		if span == nil {
			// If no active span, short circuit
			return appendMapToEnv(env, envMap)
		}

		carrier := opentracing.TextMapCarrier(envMap)
		err := span.Tracer().Inject(span.Context(), opentracing.TextMap, carrier)

		if err != nil {
			logkit.ContextLogger(ctx).WithError(err).Error("tracing span injection failed")
		}

		return appendMapToEnv(env, envMap)
	}
}