Skip to content

feat(telemetry): internal events for unit primitive usage

Shinya Maeda requested to merge track-internal-events into main

Note: This is a relatively high priority item for #491 (comment 2006453847).

What does this merge request do and why?

This MR adds request_{unit_primitive} internal event tracking to the API endpoints. This is aligned with the proposal that has been reviewed by Product Data Insights group. These internal events should contain enough information for the product request.

See Track a product usage event with the new standa... (#491 - closed) for more information.

How to set up and validate locally

See !902 (merged) for more details.

Local tests

Verified by @ankit.panchal:

Event Name Label Property Value Category
request_duo_chat duo_chat null ai_gateway.api.v1.chat.agent
request_explain_vulnerability explain_vulnerability null ai_gateway.api.v1.chat.agent
request_resolve_vulnerability resolve_vulnerability null ai_gateway.api.v1.proxy.anthropic
request_duo_chat duo_chat null ai_gateway.api.v1.proxy.vertex_ai
request_documentation_search documentation_search null ai_gateway.api.v1.search.docs
request_code_suggestions code_suggestions null ai_gateway.api.v1.x_ray.libraries
request_code_suggestions code_suggestions null ai_gateway.api.v1.code.user_access_token
request_code_suggestions code_suggestions null ai_gateway.api.v2.code.completions

Example payload

Test `v1/chat/agent` endopint
curl -X 'POST' \
  'http://0.0.0.0:5052/v1/chat/agent' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-Gitlab-Realm: saas' \
  -H 'X-Gitlab-Instance-Id: 123' \
  -H 'X-Gitlab-Host-Name: example.gitlab.com' \
  -H 'X-Gitlab-Version: 17.0' \
  -H 'X-Gitlab-Global-User-Id: 123abc' \
  -d '{
  "prompt_components": [
    {
      "type": "string",
      "metadata": {
        "source": "string",
        "version": "string"
      },
      "payload": {
        "content": "\n\nHuman: Hi, How are you?\n\nAssistant:",
        "provider": "anthropic",
        "model": "claude-2.1",
        "params": {
          "stop_sequences": [
            "\n\nHuman",
            "Observation:"
          ],
          "temperature": 0.2,
          "max_tokens_to_sample": 2048
        },
        "model_endpoint": "string",
        "model_api_key": "string"
      }
    }
  ],
  "stream": false
}'
structured event
{
  "errors": [
    "No Errors"
  ],
  "valid": true,
  "app_id": "gitlab_ai_gateway",
  "id": "2c932b72-9836-4ae5-8931-6bce0e3d691c0",
  "timestamp": "1721800027812",
  "contexts": [
    "iglu:com.gitlab/gitlab_standard/jsonschema/1-1-1"
  ],
  "event": {
    "app_id": "gitlab_ai_gateway",
    "platform": "pc",
    "etl_tstamp": "2024-07-24T05:47:07.820Z",
    "collector_tstamp": "2024-07-24T05:47:07.819Z",
    "dvce_created_tstamp": "2024-07-24T05:47:07.812Z",
    "event": "struct",
    "event_id": "2c932b72-9836-4ae5-8931-6bce0e3d691c",
    "txn_id": null,
    "name_tracker": "gl",
    "v_tracker": "py-1.0.2",
    "v_collector": "micro-ssc-2.1.0-memorysink",
    "v_etl": "snowplow-micro-2.1.0",
    "user_id": null,
    "user_ipaddress": "172.17.0.1",
    "user_fingerprint": null,
    "domain_userid": null,
    "domain_sessionidx": null,
    "network_userid": "2d350546-b402-44a7-9fcf-732dcb23f76b",
    "geo_country": null,
    "geo_region": null,
    "geo_city": null,
    "geo_zipcode": null,
    "geo_latitude": null,
    "geo_longitude": null,
    "geo_region_name": null,
    "ip_isp": null,
    "ip_organization": null,
    "ip_domain": null,
    "ip_netspeed": null,
    "page_url": null,
    "page_title": null,
    "page_referrer": null,
    "page_urlscheme": null,
    "page_urlhost": null,
    "page_urlport": null,
    "page_urlpath": null,
    "page_urlquery": null,
    "page_urlfragment": null,
    "refr_urlscheme": null,
    "refr_urlhost": null,
    "refr_urlport": null,
    "refr_urlpath": null,
    "refr_urlquery": null,
    "refr_urlfragment": null,
    "refr_medium": null,
    "refr_source": null,
    "refr_term": null,
    "mkt_medium": null,
    "mkt_source": null,
    "mkt_term": null,
    "mkt_content": null,
    "mkt_campaign": null,
    "contexts": {
      "schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",
      "data": [
        {
          "schema": "iglu:com.gitlab/gitlab_standard/jsonschema/1-1-1",
          "data": {
            "environment": "development",
            "source": "ai-gateway-python",
            "realm": "saas",
            "instance_id": "123",
            "host_name": "example.gitlab.com",
            "instance_version": "17.0",
            "global_user_id": "123abc",
            "context_generated_at": "2024-07-24T14:47:07.806081",
            "extra": {},
            "is_gitlab_team_member": null,
            "feature_enabled_by_namespace_ids": [],
            "project_id": null,
            "namespace_id": null,
            "plan": null,
            "correlation_id": "8d255303eba3497f811e3ef7dbf07f9a"
          }
        }
      ]
    },
    "se_category": "ai_gateway.api.v1.chat.agent",
    "se_action": "request_duo_chat",
    "se_label": "duo_chat",
    "se_property": null,
    "se_value": null,
    "unstruct_event": null,
    "tr_orderid": null,
    "tr_affiliation": null,
    "tr_total": null,
    "tr_tax": null,
    "tr_shipping": null,
    "tr_city": null,
    "tr_state": null,
    "tr_country": null,
    "ti_orderid": null,
    "ti_sku": null,
    "ti_name": null,
    "ti_category": null,
    "ti_price": null,
    "ti_quantity": null,
    "pp_xoffset_min": null,
    "pp_xoffset_max": null,
    "pp_yoffset_min": null,
    "pp_yoffset_max": null,
    "useragent": "python-requests/2.32.3",
    "br_name": null,
    "br_family": null,
    "br_version": null,
    "br_type": null,
    "br_renderengine": null,
    "br_lang": null,
    "br_features_pdf": null,
    "br_features_flash": null,
    "br_features_java": null,
    "br_features_director": null,
    "br_features_quicktime": null,
    "br_features_realplayer": null,
    "br_features_windowsmedia": null,
    "br_features_gears": null,
    "br_features_silverlight": null,
    "br_cookies": null,
    "br_colordepth": null,
    "br_viewwidth": null,
    "br_viewheight": null,
    "os_name": null,
    "os_family": null,
    "os_manufacturer": null,
    "os_timezone": null,
    "dvce_type": null,
    "dvce_ismobile": null,
    "dvce_screenwidth": null,
    "dvce_screenheight": null,
    "doc_charset": null,
    "doc_width": null,
    "doc_height": null,
    "tr_currency": null,
    "tr_total_base": null,
    "tr_tax_base": null,
    "tr_shipping_base": null,
    "ti_currency": null,
    "ti_price_base": null,
    "base_currency": null,
    "geo_timezone": null,
    "mkt_clickid": null,
    "mkt_network": null,
    "etl_tags": null,
    "dvce_sent_tstamp": "2024-07-24T05:47:07Z",
    "refr_domain_userid": null,
    "refr_dvce_tstamp": null,
    "derived_contexts": {},
    "domain_sessionid": null,
    "derived_tstamp": "2024-07-24T05:47:07.819Z",
    "event_vendor": "com.google.analytics",
    "event_name": "event",
    "event_format": "jsonschema",
    "event_version": "1-0-0",
    "event_fingerprint": null,
    "true_tstamp": null
  },
  "rawEvent": {
    "api": {
      "vendor": "com.snowplowanalytics.snowplow",
      "version": "tp2"
    },
    "parameters": {
      "e": "se",
      "eid": "2c932b72-9836-4ae5-8931-6bce0e3d691c",
      "aid": "gitlab_ai_gateway",
      "cx": "eyJzY2hlbWEiOiAiaWdsdTpjb20uc25vd3Bsb3dhbmFseXRpY3Muc25vd3Bsb3cvY29udGV4dHMvanNvbnNjaGVtYS8xLTAtMSIsICJkYXRhIjogW3sic2NoZW1hIjogImlnbHU6Y29tLmdpdGxhYi9naXRsYWJfc3RhbmRhcmQvanNvbnNjaGVtYS8xLTEtMSIsICJkYXRhIjogeyJlbnZpcm9ubWVudCI6ICJkZXZlbG9wbWVudCIsICJzb3VyY2UiOiAiYWktZ2F0ZXdheS1weXRob24iLCAicmVhbG0iOiAic2FhcyIsICJpbnN0YW5jZV9pZCI6ICIxMjMiLCAiaG9zdF9uYW1lIjogImV4YW1wbGUuZ2l0bGFiLmNvbSIsICJpbnN0YW5jZV92ZXJzaW9uIjogIjE3LjAiLCAiZ2xvYmFsX3VzZXJfaWQiOiAiMTIzYWJjIiwgImNvbnRleHRfZ2VuZXJhdGVkX2F0IjogIjIwMjQtMDctMjRUMTQ6NDc6MDcuODA2MDgxIiwgImV4dHJhIjoge30sICJpc19naXRsYWJfdGVhbV9tZW1iZXIiOiBudWxsLCAiZmVhdHVyZV9lbmFibGVkX2J5X25hbWVzcGFjZV9pZHMiOiBbXSwgInByb2plY3RfaWQiOiBudWxsLCAibmFtZXNwYWNlX2lkIjogbnVsbCwgInBsYW4iOiBudWxsLCAiY29ycmVsYXRpb25faWQiOiAiOGQyNTUzMDNlYmEzNDk3ZjgxMWUzZWY3ZGJmMDdmOWEifX1dfQ==",
      "tna": "gl",
      "stm": "1721800027000",
      "tv": "py-1.0.2",
      "se_ac": "request_duo_chat",
      "se_la": "duo_chat",
      "se_ca": "ai_gateway.api.v1.chat.agent",
      "p": "pc",
      "dtm": "1721800027812"
    },
    "contentType": "application/json; charset=utf-8",
    "source": {
      "name": "micro-ssc-2.1.0-memorysink",
      "encoding": "UTF-8",
      "hostname": null
    },
    "context": {
      "timestamp": "2024-07-24T05:47:07.819Z",
      "ipAddress": "172.17.0.1",
      "useragent": "python-requests/2.32.3",
      "refererUri": null,
      "headers": [
        "Host: 127.0.0.1:9091",
        "User-Agent: python-requests/2.32.3",
        "Accept-Encoding: gzip, deflate",
        "Accept: */*",
        "Connection: keep-alive",
        "Content-Type: application/json; charset=utf-8",
        "Content-Length: 1168",
        "application/json; charset=utf-8"
      ],
      "userId": "2d350546-b402-44a7-9fcf-732dcb23f76b"
    }
  },
  "schema": "iglu:com.google.analytics/event/jsonschema/1-0-0",
  "eventType": "struct",
  "eventName": "event",
  "eventVendor": "com.google.analytics"
}

Screenshot from snowplow micro:

2024-07-24_14-49

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Shinya Maeda

Merge request reports

Loading