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

feat: add manual instrumentation host functions to Go SDK #152

Merged
merged 9 commits into from
Jan 17, 2024

Conversation

mhmd-azeez
Copy link
Contributor

@mhmd-azeez mhmd-azeez commented Jan 10, 2024

After working on extism/go-sdk#47, I realized that the Go SDK is missing these host functions:

  1. span_enter
  2. span_exit
  3. metric: stubbed out
  4. log: stubbed out
  5. span_tags (only exists in the Rust API)
    • host function: ✅
    • stdout: ✅
    • datadog: ✅
    • otel: ✅

The Rust SDK seems to be more complete, so I am basing my implementation on it

@mhmd-azeez mhmd-azeez self-assigned this Jan 10, 2024
@nilslice
Copy link
Member

Awesome, thank you @mhmd-azeez! Will take a look asap

@mhmd-azeez
Copy link
Contributor Author

PS D:\dylibso\observe-sdk\go\bin\stdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm"
2024/01/15 10:46:37  Call to main took 528.8µs
2024/01/15 10:46:37  Span tags: [user_id:123 world:hello]
2024/01/15 10:46:37    Call to run took 528.8µs
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 1
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 2
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 3

@mhmd-azeez
Copy link
Contributor Author

PS D:\dylibso\observe-sdk\go\bin\otelstdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm" | jq
{
  "resource_spans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "Value": {
                "StringValue": "golang"
              }
            }
          }
        ]
      },
      "scope_spans": [
        {
          "spans": [
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "35Wkp/0KIWo=",
              "name": "main",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-main"
                    }
                  }
                },
                {
                  "key": "user_id",
                  "value": {
                    "Value": {
                      "StringValue": "123"
                    }
                  }
                },
                {
                  "key": "world",
                  "value": {
                    "Value": {
                      "StringValue": "hello"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "CMh6L6C2R2g=",
              "parent_span_id": "35Wkp/0KIWo=",
              "name": "run",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-run"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "jVBdEHFklXA=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "T3Ag7YUsjA8=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "wrD9SH0shGU=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

@bhelx
Copy link
Contributor

bhelx commented Jan 15, 2024

As we discussed in meeting. let's print out metrics and logs for the time being and note that they aren't sent to sink yet. we can circle back around on it. We may want to decide and build out some of this stuff before wasm i/o

@mhmd-azeez mhmd-azeez marked this pull request as ready for review January 16, 2024 14:30
@mhmd-azeez
Copy link
Contributor Author

I have stubbed out the implementation for metrics and logs for now:

PS D:\dylibso\observe-sdk\go\bin\stdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm"
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 1
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 2
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 3
2024/01/16 17:33:23  Call to main took 0s
2024/01/16 17:33:23  Span tags: [user_id:123 world:hello]
2024/01/16 17:33:23    Call to run took 0s
2024/01/16 17:33:23      Call to log_something took 0s
2024/01/16 17:33:23      Call to log_something took 0s
2024/01/16 17:33:23      Call to log_something took 0s
PS D:\dylibso\observe-sdk\go\bin\otelstdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm" | jq
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 1
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 2
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 3
{
  "resource_spans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "Value": {
                "StringValue": "golang"
              }
            }
          }
        ]
      },
      "scope_spans": [
        {
          "spans": [
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "PPDLcpkhTSI=",
              "name": "main",
              "kind": 1,
              "start_time_unix_nano": 1705415619995863400,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-main"
                    }
                  }
                },
                {
                  "key": "user_id",
                  "value": {
                    "Value": {
                      "StringValue": "123"
                    }
                  }
                },
                {
                  "key": "world",
                  "value": {
                    "Value": {
                      "StringValue": "hello"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "ke5RPsvFkyI=",
              "parent_span_id": "PPDLcpkhTSI=",
              "name": "run",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-run"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "PX+BGZP5mVE=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "nlTNTMVIV2A=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "sNWOxpH+OVY=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Copy link
Contributor

@bhelx bhelx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you :)

@mhmd-azeez mhmd-azeez merged commit 7c028e0 into main Jan 17, 2024
6 checks passed
@mhmd-azeez mhmd-azeez deleted the manual_instrumentation branch January 17, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants