Reference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::Project.
Project
Projects are top-level containers in Google Cloud Platform. They store
information about billing and authorized users, and they control access
to Stackdriver Trace resources. Each project has a friendly name and a
unique ID. Projects can be created only in the Google Developers
Console.
This class is a client to make API calls for the project's trace data.
Create an instance using new or
Google::Cloud#trace. You may then use the get_trace method to
retrieve a trace by ID, list_traces to query for a set of traces,
and patch_traces to update trace data. You may also use new_trace
as a convenience constructor to build a
TraceRecord object.
Returns of a list of traces that match the specified conditions.
You must provide a time interval. You may optionally provide a
filter, an ordering, a view type.
Results are paginated, and you may specify a page size. The result
will come with a token you can pass back to retrieve the next page.
Parameters
start_time (Time) — The start of the time interval (inclusive).
end_time (Time) — The end of the time interval (inclusive).
filter (String) (defaults to: nil) — An optional filter.
order_by (String) (defaults to: nil) — The optional sort order for returned traces.
May be trace_id, name, duration, or start. Any sort order
may also be reversed by appending desc; for example use
start desc to order traces from newest to oldest.
view (Symbol) (defaults to: nil) — The optional type of view. Valid values are
:MINIMAL, :ROOTSPAN, and :COMPLETE. Default is :MINIMAL.
page_size (Integer) (defaults to: nil) — The size of each page to return. Optional;
if omitted, the service will select a reasonable page size.
page_token (String) (defaults to: nil) — A token indicating the page to return.
Each page of results includes proper token for specifying the
following page.
Create a new empty trace record for this project. Uses the current
thread's TraceContext by default; otherwise you may provide a
specific TraceContext.
Parameter
trace_context (Stackdriver::Core::TraceContext, nil) (defaults to: :DEFAULT) — The
context within which to locate this trace (i.e. sets the trace ID
and the context parent span, if present.) If the context is set
explicitly to nil, a new trace with a new trace ID is created.
If no context is provided, the current thread's context is used.
Sends new traces to Stackdriver Trace or updates existing traces.
If the ID of a trace that you send matches that of an existing trace,
any fields in the existing trace and its spans are overwritten by the
provided values, and any new fields provided are merged with the
existing trace data. If the ID does not match, a new trace is created.
Parameter
traces (Google::Cloud::Trace::TraceRecord, Array{Google::Cloud::Trace::TraceRecord}) — Either a single
trace object or an array of trace objects.
Returns
(Array{Google::Cloud::Trace::TraceRecord}) — The traces written.
Example
require"google/cloud/trace"trace_client=Google::Cloud::Trace.newtrace=trace_client.new_tracetrace.in_span"root_span"do# Do stuff...endtrace_client.patch_tracestrace
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Trace API - Class Google::Cloud::Trace::Project (v0.45.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-Project)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/Google-Cloud-Trace-Project)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/Google-Cloud-Trace-Project)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/Google-Cloud-Trace-Project)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/Google-Cloud-Trace-Project) \nReference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::Project.\n\nProject\n-------\n\nProjects are top-level containers in Google Cloud Platform. They store\ninformation about billing and authorized users, and they control access\nto Stackdriver Trace resources. Each project has a friendly name and a\nunique ID. Projects can be created only in the [Google Developers\nConsole](https://console.developers.google.com).\n\nThis class is a client to make API calls for the project's trace data.\nCreate an instance using [new](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace#Google__Cloud__Trace_new_class_ \"Google::Cloud::Trace.new (method)\") or\n[Google::Cloud#trace](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud#Google__Cloud_trace_instance_ \"Google::Cloud#trace (method)\"). You may then use the `get_trace` method to\nretrieve a trace by ID, `list_traces` to query for a set of traces,\nand `patch_traces` to update trace data. You may also use `new_trace`\nas a convenience constructor to build a\n[TraceRecord](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-TraceRecord \"Google::Cloud::Trace::TraceRecord (class)\") object. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new\ntraces = trace_client.list_traces Time.now - 3600, Time.now\n```\n\nMethods\n-------\n\n### #get_trace\n\n def get_trace(trace_id) -\u003e Google::Cloud::Trace::TraceRecord, nil\n\nGets a single trace by its ID. \n**Parameter**\n\n- **trace_id** (String) --- The ID of the trace to fetch. \n**Returns**\n\n- ([Google::Cloud::Trace::TraceRecord](./Google-Cloud-Trace-TraceRecord), nil) --- The trace object, or `nil` if there is no accessible trace with the given ID.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new\n\ntrace = trace_client.get_trace \"1234567890abcdef1234567890abcdef\"\n```\n\n### #list_traces\n\n def list_traces(start_time, end_time, filter: nil, order_by: nil, view: nil, page_size: nil, page_token: nil) -\u003e Google::Cloud::Trace::ResultSet\n\nReturns of a list of traces that match the specified conditions.\nYou must provide a time interval. You may optionally provide a\nfilter, an ordering, a view type.\nResults are paginated, and you may specify a page size. The result\nwill come with a token you can pass back to retrieve the next page. \n**Parameters**\n\n- **start_time** (Time) --- The start of the time interval (inclusive).\n- **end_time** (Time) --- The end of the time interval (inclusive).\n- **filter** (String) *(defaults to: nil)* --- An optional filter.\n- **order_by** (String) *(defaults to: nil)* --- The optional sort order for returned traces. May be `trace_id`, `name`, `duration`, or `start`. Any sort order may also be reversed by appending `desc`; for example use `start desc` to order traces from newest to oldest.\n- **view** (Symbol) *(defaults to: nil)* --- The optional type of view. Valid values are `:MINIMAL`, `:ROOTSPAN`, and `:COMPLETE`. Default is `:MINIMAL`.\n- **page_size** (Integer) *(defaults to: nil)* --- The size of each page to return. Optional; if omitted, the service will select a reasonable page size.\n- **page_token** (String) *(defaults to: nil)* --- A token indicating the page to return. Each page of results includes proper token for specifying the following page. \n**Returns**\n\n- ([Google::Cloud::Trace::ResultSet](./Google-Cloud-Trace-ResultSet)) --- A page of results.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new\n\ntraces = trace_client.list_traces Time.now - 3600, Time.now\ntraces.each do |trace|\n puts \"Retrieved trace ID: #{trace.trace_id}\"\nend\n```\n\n### #new_trace\n\n def new_trace(trace_context: :DEFAULT) -\u003e Google::Cloud::Trace::TraceRecord\n\nCreate a new empty trace record for this project. Uses the current\nthread's TraceContext by default; otherwise you may provide a\nspecific TraceContext. \n**Parameter**\n\n- **trace_context** (Stackdriver::Core::TraceContext, nil) *(defaults to: :DEFAULT)* --- The context within which to locate this trace (i.e. sets the trace ID and the context parent span, if present.) If the context is set explicitly to `nil`, a new trace with a new trace ID is created. If no context is provided, the current thread's context is used. \n**Returns**\n\n- ([Google::Cloud::Trace::TraceRecord](./Google-Cloud-Trace-TraceRecord)) --- The new trace.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new(\n project_id: \"my-project\",\n credentials: \"/path/to/keyfile.json\"\n)\n\ntrace = trace_client.new_trace\n```\n\n### #patch_traces\n\n def patch_traces(traces) -\u003e Array{Google::Cloud::Trace::TraceRecord}\n\nSends new traces to Stackdriver Trace or updates existing traces.\nIf the ID of a trace that you send matches that of an existing trace,\nany fields in the existing trace and its spans are overwritten by the\nprovided values, and any new fields provided are merged with the\nexisting trace data. If the ID does not match, a new trace is created. \n**Parameter**\n\n- **traces** ([Google::Cloud::Trace::TraceRecord](./Google-Cloud-Trace-TraceRecord), Array{Google::Cloud::Trace::TraceRecord}) --- Either a single trace object or an array of trace objects. \n**Returns**\n\n- (Array{Google::Cloud::Trace::TraceRecord}) --- The traces written.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new\n\ntrace = trace_client.new_trace\ntrace.in_span \"root_span\" do\n # Do stuff...\nend\n\ntrace_client.patch_traces trace\n```\n\n### #project\n\n def project() -\u003e String\n\n**Alias Of** : [#project_id](./Google-Cloud-Trace-Project#Google__Cloud__Trace__Project_project_id_instance_) \nThe ID of the current project. \n**Returns**\n\n- (String) --- the Google Cloud project ID\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new(\n project_id: \"my-project\",\n credentials: \"/path/to/keyfile.json\"\n)\n\ntrace_client.project_id #=\u003e \"my-project\"\n```\n\n### #project_id\n\n def project_id() -\u003e String\n\n**Aliases**\n\n- [#project](./Google-Cloud-Trace-Project#Google__Cloud__Trace__Project_project_instance_) \nThe ID of the current project. \n**Returns**\n\n- (String) --- the Google Cloud project ID\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_client = Google::Cloud::Trace.new(\n project_id: \"my-project\",\n credentials: \"/path/to/keyfile.json\"\n)\n\ntrace_client.project_id #=\u003e \"my-project\"\n```"]]