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

keyvault packages mutate passed spanOptions #5190

Closed
xirzec opened this issue Sep 19, 2019 · 0 comments
Closed

keyvault packages mutate passed spanOptions #5190

xirzec opened this issue Sep 19, 2019 · 0 comments
Assignees
Labels

Comments

@xirzec
Copy link
Member

xirzec commented Sep 19, 2019

  • Package Name: keyvault-certificates, keyvault-keys, keyvault-secrets
  • Package Version: 4.0.0-preview.6

Describe the bug

Operations can take a manual tracing span like this

const result = await client.createKey(keyName, "EC", {
      requestOptions: {
        spanOptions: {
          parent: rootSpan
        }
      }
    });

The problem arises that under the covers these libraries mutate spanOptions inside a private createSpan helper:

  /**
   * Creates a span using the tracer that was set by the user
   * @param methodName The name of the method for which the span is being created.
   * @param requestOptions The options for the underlying http request. This will be
   * updated to use the newly created span as the "parent" so that any new spans created
   * after this point gets the right parent.
   */
  private createSpan(methodName: string, requestOptions?: RequestOptionsBase): Span {
    const tracer = TracerProxy.getTracer();
    const options = requestOptions || {};
    const span = tracer.startSpan(methodName, options.spanOptions);
    if (
      tracer.pluginType !== SupportedPlugins.NOOP &&
      (options.spanOptions && options.spanOptions.parent)
    ) {
      options.spanOptions = { ...options.spanOptions, parent: span };
    }
    return span;
  }
}

The issue being that if a user does two operations with a re-used options bag (expecting reasonably that their options would not be mutated), the tracing graph will be incorrect:

const requestOptions = {
  spanOptions: {
    parent: rootSpan
  }
};
const result = await client.createKey(keyName, "AB", { requestOptions});
const result2 = await client.createKey(keyName, "CD", { requestOptions});

The expectation is that the above operations would have the same parent root span, but currently the second createKey would be parented under the first.

@xirzec xirzec self-assigned this Sep 19, 2019
@xirzec xirzec closed this as completed in 5303102 Sep 26, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant