Skip to content

Deprecate TransactionContext functions #454

Description

@sahidvelji

Related to #413

// WithTransactionContext constructs a TransactionContext.
//
// ctx - the context to embed the EvaluationContext in
// ec - the EvaluationContext to embed into the context
func WithTransactionContext(ctx context.Context, ec EvaluationContext) context.Context {
return context.WithValue(ctx, internal.TransactionContext, ec)
}
// MergeTransactionContext merges the provided EvaluationContext with the current TransactionContext (if it exists)
//
// ctx - the context to pull existing TransactionContext from
// ec - the EvaluationContext to merge with the existing TransactionContext
func MergeTransactionContext(ctx context.Context, ec EvaluationContext) context.Context {
oldTc := TransactionContext(ctx)
mergedTc := mergeContexts(ec, oldTc)
return WithTransactionContext(ctx, mergedTc)
}
// TransactionContext extracts a EvaluationContext from the current
// golang.org/x/net/context. if no EvaluationContext exist, it will construct
// an empty EvaluationContext
//
// ctx - the context to pull EvaluationContext from
func TransactionContext(ctx context.Context) EvaluationContext {
ec, ok := ctx.Value(internal.TransactionContext).(EvaluationContext)
if !ok {
return EvaluationContext{}
}
return ec
}

My proposal is that we deprecate these functions and turn them into package-level variables that are assigned to the new functions.

See the OTel trace package for good names for these types of functions.
The convention here is TypeNameFromContext and ContextWithTypeName, where TypeName is the name of the type of identifier being stored/retrieved from the context.

Note that MergeTransactionContext will be handled in a separate issue, as it's a bit more involved.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions