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

Support access to ITracingContext through static property. #540

Merged
merged 6 commits into from
Feb 21, 2023

Conversation

inversionhourglass
Copy link
Contributor

Please answer these questions before submitting pull request

  • Why submit this pull request?

  • Bug fix

  • New feature provided

  • Improve performance

  • Related issues


Bug fix

  • Bug description.

  • How to fix?


New feature or improvement

  • Describe the details and related test reports.
    The current pr adds the SkyApm.Utilities.StaticAccessor project, which provides static properties for accessing ITracingContext, which is convenient for creating a Segment in a static method.
    有时候我们需要在静态方法中创建segment,当前PR中的SkyApm.Utilities.StaticAccessor项目提供了静态属性访问ITracingContext
// 1. add SkyApm.Utilities.StaticAccessor package reference
// dotnet add package SkyApm.Utilities.StaticAccessor

// 2. enable in startup
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // ...

        services.AddSkyAPMStaticAccessor();
    }
}

// 3. use it in static method
static async Task M()
{
    var context = SkyApm.Utilities.StaticAccessor.TracingContext.CreateLocalSegmentContext("test");
    await Task.Delay(100);
    SkyApm.Utilities.StaticAccessor.TracingContext.Release(context);
}

@wu-sheng
Copy link
Member

@liuhaoyang I am not sure whether this is a good way to access the agent kernel. This looks like direct accessing. Usually, we should think the agent could be removed at any moment. The API bridge should be able to fall back to no agent mode.

@inversionhourglass
Copy link
Contributor Author

inversionhourglass commented Feb 20, 2023

Usually, we should think the agent could be removed at any moment. The API bridge should be able to fall back to no agent mode.

In the new commit, I added processing logic, even if the agent is disabled(by remove environment), there will be no error because of this function. Of course, if @liuhaoyang thinks that this function can be added to AddSkyAPMCore as a default extension, then the first step(install package) and the second step(enable in startup) also be omitted.

在新的提交中我增加了处理逻辑,即使agent被禁用了也不会因为该功能而出现错误,当然如果 @liuhaoyang 认为该功能可以添加到 AddSkyAPMCore 中作为一个默认的扩展,那么第一步和第二步都可以省略。

@wu-sheng
Copy link
Member

Let's wait for @liuhaoyang

@liuhaoyang
Copy link
Collaborator

Good idea! I will review the code tomorrow.

@liuhaoyang liuhaoyang merged commit 7e7693d into SkyAPM:main Feb 21, 2023
@wu-sheng wu-sheng added this to the 2.2.0 milestone Feb 21, 2023
@wu-sheng wu-sheng added the enhancement New feature or request label Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants