Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: add trace id to http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Wagner committed Jan 14, 2024
1 parent 2779aba commit 7eaaa3b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion planqk/qiskit/client/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import json
import logging
import os
import random
from typing import List, Optional, Callable, Any, Dict

import requests
from requests import Response, HTTPError

from planqk.context import ContextResolver
from planqk.credentials import DefaultCredentialsProvider
from planqk.exceptions import InvalidAccessTokenError, PlanqkClientError
from planqk.qiskit.client.backend_dtos import BackendDto, PROVIDER, BackendStateInfosDto
from planqk.qiskit.client.job_dtos import JobDto
from requests import Response, HTTPError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -134,10 +136,17 @@ def _get_default_headers(cls):
if context is not None and context.is_organization:
headers["x-organizationid"] = context.get_organization_id()

headers["x-cloud-trace-context"] = cls._generate_trace_id()
logger.debug("PlanQK client request trace id: %s", headers["x-cloud-trace-context"])

return headers

@classmethod
def remove_none_values(cls, d):
if not isinstance(d, dict):
return d
return {k: cls.remove_none_values(v) for k, v in d.items() if v is not None}

@classmethod
def _generate_trace_id(cls):
return '{:032x}'.format(random.getrandbits(128))

0 comments on commit 7eaaa3b

Please sign in to comment.