def __init__(self, client=None, project_id=None):
        # The client will handler the case when project_id is None
        if client is None:
            client = Client(project=project_id)

        self.client = client
        self.project_id = client.project
Exemple #2
0
    def __init__(self, client=None, project_id=None, transport=AsyncTransport):
        # The client will handle the case when project_id is None
        if client is None:
            client = Client(project=project_id)

        self.client = client
        self.project_id = client.project
        self.transport = transport(self)
Exemple #3
0
def get_client(**kwargs):
    encoded_key = os.environ.get("GCP_TRACING_SERVICE_ACCOUNT")
    if not encoded_key:
        raise RuntimeError("missing GCP_TRACING_SERVICE_ACCOUNT")
    service_account_key = json.loads(base64.b64decode(encoded_key))
    project_id = service_account_key["project_id"]
    credentials = service_account.Credentials.from_service_account_info(service_account_key)
    scoped_credentials = credentials.with_scopes([
        "https://www.googleapis.com/auth/trace.append",
    ])
    return Client(project=project_id, credentials=scoped_credentials, **kwargs)