MCPcopy Create free account
hub / github.com/getsentry/sentry / load_data

Function load_data

src/sentry/utils/samples.py:108–309  ·  view source on GitHub ↗
(
    platform: str,
    default: str | None = None,
    sample_name: str | None = None,
    timestamp=None,
    start_timestamp=None,
    trace: str | None = None,
    span_id: str | None = None,
    spans=None,
    trace_context=None,
    fingerprint=None,
    event_id=None,
)

Source from the content-addressed store, hash-verified

106
107
108def load_data(
109 platform: str,
110 default: str | None = None,
111 sample_name: str | None = None,
112 timestamp=None,
113 start_timestamp=None,
114 trace: str | None = None,
115 span_id: str | None = None,
116 spans=None,
117 trace_context=None,
118 fingerprint=None,
119 event_id=None,
120):
121 # NOTE: Before editing this data, make sure you understand the context
122 # in which its being used. It is NOT only used for local development and
123 # has production consequences.
124 # * bin/load-mocks to generate fake data for local testing
125 # * When a new project is created, a fake event is generated as a "starter"
126 # event so it's not an empty project.
127 # * When a user clicks Test Configuration from notification plugin settings page,
128 # a fake event is generated to go through the pipeline.
129 data = None
130 language = None
131 platform_data = INTEGRATION_ID_TO_PLATFORM_DATA.get(platform)
132
133 if platform_data is not None and platform_data["type"] != "language":
134 language = platform_data["language"]
135
136 samples_root = os.path.join(DATA_ROOT, "samples")
137
138 # this loop will try to load the specified platform first, but if we do not
139 # have a specific sample for it, we then move on to the `language`, then the `default`.
140 # The `default` is set to `javascript` in ./src/sentry/api/endpoints/project_create_sample.py
141 # on the `ProjectCreateSampleEndpoint`
142 for sample in (platform, language, default):
143 if not sample:
144 continue
145
146 # Verify the requested path is valid and disallow path traversal attempts
147 json_file = f"{sample}.json"
148
149 expected_commonpath = os.path.realpath(
150 samples_root
151 ) # .realpath() ensures symlinks are handled
152 json_path = os.path.join(samples_root, json_file)
153 json_real_path = os.path.realpath(json_path)
154
155 if expected_commonpath != os.path.commonpath([expected_commonpath, json_real_path]):
156 raise SuspiciousFileOperation("potential path traversal attack detected")
157
158 # the requested `sample` does not exist, so continue through to the next iteration
159 if not os.path.exists(json_path):
160 continue
161
162 if not os.path.isfile(json_path):
163 raise IsADirectoryError("expected file but found a directory instead")
164
165 if not sample_name:

Callers 15

store_functionsMethod · 0.90
load_dataMethod · 0.90
create_eventMethod · 0.90
load_errorsMethod · 0.90
make_error_eventFunction · 0.90
make_performance_eventFunction · 0.90
getMethod · 0.90
digestFunction · 0.90

Calls 13

deprecated_utcnowFunction · 0.90
roundFunction · 0.85
generate_userFunction · 0.85
splitMethod · 0.80
getMethod · 0.65
loadMethod · 0.65
openFunction · 0.50
joinMethod · 0.45
existsMethod · 0.45
replaceMethod · 0.45
timestampMethod · 0.45
updateMethod · 0.45